| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
3 files changed
| 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 | |
|---|---|---|---|
@@ -41,6 +41,9 @@ Core and Builtins | |||
| 41 | 41 | Library | |
| 42 | 42 | ------- | |
| 43 | 43 | ||
| 44 | + - Issue #27897: Fixed possible crash in sqlite3.Connection.create_collation() | ||
| 45 | + if pass invalid string-like object as a name. Patch by Xiang Zhang. | ||
| 46 | + | ||
| 44 | 47 | - Issue #18893: Fix invalid exception handling in Lib/ctypes/macholib/dyld.py. | |
| 45 | 48 | Patch by Madison May. | |
| 46 | 49 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1498,11 +1498,13 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args) | |||
| 1498 | 1498 | goto finally; | |
| 1499 | 1499 | } | |
| 1500 | 1500 | ||
| 1501 | - if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyUnicode_Type, &name, &callable)) { | ||
| 1501 | + if (!PyArg_ParseTuple(args, "UO:create_collation(name, callback)", | ||
| 1502 | + &name, &callable)) { | ||
| 1502 | 1503 | goto finally; | |
| 1503 | 1504 | } | |
| 1504 | 1505 | ||
| 1505 | - uppercase_name = _PyObject_CallMethodId(name, &PyId_upper, NULL); | ||
| 1506 | + uppercase_name = _PyObject_CallMethodIdObjArgs((PyObject *)&PyUnicode_Type, | ||
| 1507 | + &PyId_upper, name, NULL); | ||
| 1506 | 1508 | if (!uppercase_name) { | |
| 1507 | 1509 | goto finally; | |
| 1508 | 1510 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments