Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,12 @@ def test_blob_get_slice(self):
def test_blob_get_empty_slice(self):
self.assertEqual(self.blob[5:5], b"")

def test_blob_get_empty_slice_oob_indices(self):
self.cx.execute("delete from test")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to leave this out. Just add a new row and blobopen it instead. Alternatively, make the test work with the pre-filled data in the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erlend-aasland The test has been updated.

self.cx.execute("insert into test(b) values (?)", (b"abc",))
with self.cx.blobopen("test", "b", 1) as blob:
self.assertEqual(blob[5:-5], b"")

def test_blob_get_slice_negative_index(self):
self.assertEqual(self.blob[5:-5], self.data[5:-5])

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix assertion failure in :mod:`sqlite3` blob subscript when slicing with
indices that result in an empty slice.
4 changes: 4 additions & 0 deletions Modules/_sqlite/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ subscript_slice(pysqlite_Blob *self, PyObject *item)
return NULL;
}

if (len == 0) {
return PyBytes_FromStringAndSize(NULL, 0);
}

if (step == 1) {
return read_multiple(self, len, start);
}
Expand Down
Loading