| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2d3d11c commit 62f4782
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1408,6 +1408,18 @@ def test_blob_set_empty_slice(self): | |||
| 1408 | 1408 | self.blob[0:0] = b"" | |
| 1409 | 1409 | self.assertEqual(self.blob[:], self.data) | |
| 1410 | 1410 | ||
| 1411 | + def test_blob_set_empty_slice_wrong_type(self): | ||
| 1412 | + with self.assertRaises(TypeError): | ||
| 1413 | + self.blob[5:5] = None | ||
| 1414 | + | ||
| 1415 | + def test_blob_set_empty_slice_wrong_size(self): | ||
| 1416 | + with self.assertRaisesRegex(IndexError, "wrong size"): | ||
| 1417 | + self.blob[5:5] = b"123" | ||
| 1418 | + | ||
| 1419 | + def test_blob_set_empty_slice_correct(self): | ||
| 1420 | + self.blob[5:5] = b"" | ||
| 1421 | + self.assertEqual(self.blob[:], self.data) | ||
| 1422 | + | ||
| 1411 | 1423 | def test_blob_set_slice_with_skip(self): | |
| 1412 | 1424 | self.blob[0:10:2] = b"12345" | |
| 1413 | 1425 | actual = self.cx.execute("select b from test").fetchone()[0] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Fix :class:`sqlite3.Blob` slice assignment to raise | ||
| 2 | + :exc:`TypeError` and :exc:`IndexError` for type and size mismatches | ||
| 3 | + respectively, even when the target slice is empty. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -524,21 +524,25 @@ ass_subscript_slice(pysqlite_Blob *self, PyObject *item, PyObject *value) | |||
| 524 | 524 | return -1; | |
| 525 | 525 | } | |
| 526 | 526 | ||
| 527 | - if (len == 0) { | ||
| 528 | - return 0; | ||
| 529 | - } | ||
| 530 | - | ||
| 531 | 527 | Py_buffer vbuf; | |
| 532 | 528 | if (PyObject_GetBuffer(value, &vbuf, PyBUF_SIMPLE) < 0) { | |
| 533 | 529 | return -1; | |
| 534 | 530 | } | |
| 535 | 531 | ||
| 536 | - int rc = -1; | ||
| 537 | 532 | if (vbuf.len != len) { | |
| 538 | 533 | PyErr_SetString(PyExc_IndexError, | |
| 539 | 534 | "Blob slice assignment is wrong size"); | |
| 535 | + PyBuffer_Release(&vbuf); | ||
| 536 | + return -1; | ||
| 540 | 537 | } | |
| 541 | - else if (step == 1) { | ||
| 538 | + | ||
| 539 | + if (len == 0) { | ||
| 540 | + PyBuffer_Release(&vbuf); | ||
| 541 | + return 0; | ||
| 542 | + } | ||
| 543 | + | ||
| 544 | + int rc = -1; | ||
| 545 | + if (step == 1) { | ||
| 542 | 546 | rc = inner_write(self, vbuf.buf, len, start); | |
| 543 | 547 | } | |
| 544 | 548 | else { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments