| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,11 @@ | |||
| 25 | 25 | import sqlite3 as sqlite | |
| 26 | 26 | ||
| 27 | 27 | class CollationTests(unittest.TestCase): | |
| 28 | + def CheckCreateCollationNotString(self): | ||
| 29 | + con = sqlite.connect(":memory:") | ||
| 30 | + with self.assertRaises(TypeError): | ||
| 31 | + con.create_collation(None, lambda x, y: (x > y) - (x < y)) | ||
| 32 | + | ||
| 28 | 33 | def CheckCreateCollationNotCallable(self): | |
| 29 | 34 | con = sqlite.connect(":memory:") | |
| 30 | 35 | with self.assertRaises(TypeError) as cm: | |
@@ -36,6 +41,23 @@ def CheckCreateCollationNotAscii(self): | |||
| 36 | 41 | with self.assertRaises(sqlite.ProgrammingError): | |
| 37 | 42 | con.create_collation("collä", lambda x, y: (x > y) - (x < y)) | |
| 38 | 43 | ||
| 44 | + def CheckCreateCollationBadUpper(self): | ||
| 45 | + class BadUpperStr(str): | ||
| 46 | + def upper(self): | ||
| 47 | + return None | ||
| 48 | + con = sqlite.connect(":memory:") | ||
| 49 | + mycoll = lambda x, y: -((x > y) - (x < y)) | ||
| 50 | + con.create_collation(BadUpperStr("mycoll"), mycoll) | ||
| 51 | + result = con.execute(""" | ||
| 52 | + select x from ( | ||
| 53 | + select 'a' as x | ||
| 54 | + union | ||
| 55 | + select 'b' as x | ||
| 56 | + ) order by x collate mycoll | ||
| 57 | + """).fetchall() | ||
| 58 | + self.assertEqual(result[0][0], 'b') | ||
| 59 | + self.assertEqual(result[1][0], 'a') | ||
| 60 | + | ||
| 39 | 61 | @unittest.skipIf(sqlite.sqlite_version_info < (3, 2, 1), | |
| 40 | 62 | 'old SQLite versions crash on this test') | |
| 41 | 63 | def CheckCollationIsUsed(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,6 +80,9 @@ Core and Builtins | |||
| 80 | 80 | Library | |
| 81 | 81 | ------- | |
| 82 | 82 | ||
| 83 | + - Issue #27897: Fixed possible crash in sqlite3.Connection.create_collation() | ||
| 84 | + if pass invalid string-like object as a name. Patch by Xiang Zhang. | ||
| 85 | + | ||
| 83 | 86 | - Issue #18893: Fix invalid exception handling in Lib/ctypes/macholib/dyld.py. | |
| 84 | 87 | Patch by Madison May. | |
| 85 | 88 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1523,11 +1523,13 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args) | |||
| 1523 | 1523 | goto finally; | |
| 1524 | 1524 | } | |
| 1525 | 1525 | ||
| 1526 | - if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyUnicode_Type, &name, &callable)) { | ||
| 1526 | + if (!PyArg_ParseTuple(args, "UO:create_collation(name, callback)", | ||
| 1527 | + &name, &callable)) { | ||
| 1527 | 1528 | goto finally; | |
| 1528 | 1529 | } | |
| 1529 | 1530 | ||
| 1530 | - uppercase_name = _PyObject_CallMethodId(name, &PyId_upper, ""); | ||
| 1531 | + uppercase_name = _PyObject_CallMethodIdObjArgs((PyObject *)&PyUnicode_Type, | ||
| 1532 | + &PyId_upper, name, NULL); | ||
| 1531 | 1533 | if (!uppercase_name) { | |
| 1532 | 1534 | goto finally; | |
| 1533 | 1535 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments