Index: Lib/sqlite3/test/regression.py =================================================================== --- Lib/sqlite3/test/regression.py (révision 79254) +++ Lib/sqlite3/test/regression.py (copie de travail) @@ -274,6 +274,13 @@ """ self.assertRaises(sqlite.Warning, self.con, 1) + def CheckCollation(self): + def collation_cb(a, b): + return 1 + self.assertRaises(sqlite.ProgrammingError, self.con.create_collation, + # Lone surrogate cannot be encoded to the default encoding (utf8) + "\uDC80", collation_cb) + def suite(): regression_suite = unittest.makeSuite(RegressionTests, "Check") return unittest.TestSuite((regression_suite,)) Index: Modules/_sqlite/connection.c =================================================================== --- Modules/_sqlite/connection.c (révision 79254) +++ Modules/_sqlite/connection.c (copie de travail) @@ -3,7 +3,7 @@ * Copyright (C) 2004-2010 Gerhard Häring * * This file is part of pysqlite. - * + * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. @@ -892,7 +892,7 @@ } /* abort query if error occurred */ - rc = 1; + rc = 1; } else { rc = (int)PyObject_IsTrue(ret); Py_DECREF(ret); @@ -1374,7 +1374,9 @@ PyObject* uppercase_name = 0; PyObject* name; PyObject* retval; - char* chk; + Py_UNICODE* chk; + Py_ssize_t i, len; + char *uppercase_name_str; int rc; if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { @@ -1390,19 +1392,23 @@ goto finally; } - chk = _PyUnicode_AsString(uppercase_name); - while (*chk) { - if ((*chk >= '0' && *chk <= '9') - || (*chk >= 'A' && *chk <= 'Z') - || (*chk == '_')) + len = PyUnicode_GET_SIZE(uppercase_name); + chk = PyUnicode_AS_UNICODE(uppercase_name); + for (i=0; i= (Py_UNICODE)'0' && *chk <= (Py_UNICODE)'9') + || (*chk >= (Py_UNICODE)'A' && *chk <= (Py_UNICODE)'Z') + || (*chk == (Py_UNICODE)'_')) { - chk++; - } else { - PyErr_SetString(pysqlite_ProgrammingError, "invalid character in collation name"); - goto finally; + continue; } + PyErr_SetString(pysqlite_ProgrammingError, "invalid character in collation name"); + goto finally; } + uppercase_name_str = _PyUnicode_AsString(uppercase_name); + if (!uppercase_name_str) + goto finally; + if (callable != Py_None && !PyCallable_Check(callable)) { PyErr_SetString(PyExc_TypeError, "parameter must be callable"); goto finally; @@ -1417,7 +1423,7 @@ } rc = sqlite3_create_collation(self->db, - _PyUnicode_AsString(uppercase_name), + uppercase_name_str, SQLITE_UTF8, (callable != Py_None) ? callable : NULL, (callable != Py_None) ? pysqlite_collation_callback : NULL);