diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-08-06 21:02:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-06 21:02:06 (GMT) |
commit | c352412123140e79dcce6188d17e3e6dbc3f4144 (patch) | |
tree | 2279260ecf95eea0c1e158a8a44235e2e67a6d25 /Lib/sqlite3 | |
parent | 62bce24e32a9c754a23e758a32a7e0ca49602fc5 (diff) | |
download | cpython-c352412123140e79dcce6188d17e3e6dbc3f4144.zip cpython-c352412123140e79dcce6188d17e3e6dbc3f4144.tar.gz cpython-c352412123140e79dcce6188d17e3e6dbc3f4144.tar.bz2 |
[3.9] bpo-44822: Don't truncate `str`s with embedded NULL chars returned by `sqlite3` UDF callbacks (GH-27588). (GH-27639)
(cherry picked from commit 8f010dc920e1f6dc6a357e7cc1460a7a567c05c6)
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r-- | Lib/sqlite3/test/userfunctions.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/sqlite3/test/userfunctions.py b/Lib/sqlite3/test/userfunctions.py index a1c29d4..1bceefe 100644 --- a/Lib/sqlite3/test/userfunctions.py +++ b/Lib/sqlite3/test/userfunctions.py @@ -27,6 +27,8 @@ import sqlite3 as sqlite def func_returntext(): return "foo" +def func_returntextwithnull(): + return "1\x002" def func_returnunicode(): return "bar" def func_returnint(): @@ -137,11 +139,21 @@ class AggrSum: def finalize(self): return self.val +class AggrText: + def __init__(self): + self.txt = "" + def step(self, txt): + self.txt = self.txt + txt + def finalize(self): + return self.txt + + class FunctionTests(unittest.TestCase): def setUp(self): self.con = sqlite.connect(":memory:") self.con.create_function("returntext", 0, func_returntext) + self.con.create_function("returntextwithnull", 0, func_returntextwithnull) self.con.create_function("returnunicode", 0, func_returnunicode) self.con.create_function("returnint", 0, func_returnint) self.con.create_function("returnfloat", 0, func_returnfloat) @@ -185,6 +197,12 @@ class FunctionTests(unittest.TestCase): self.assertEqual(type(val), str) self.assertEqual(val, "foo") + def CheckFuncReturnTextWithNullChar(self): + cur = self.con.cursor() + res = cur.execute("select returntextwithnull()").fetchone()[0] + self.assertEqual(type(res), str) + self.assertEqual(res, "1\x002") + def CheckFuncReturnUnicode(self): cur = self.con.cursor() cur.execute("select returnunicode()") @@ -343,6 +361,7 @@ class AggregateTests(unittest.TestCase): self.con.create_aggregate("checkType", 2, AggrCheckType) self.con.create_aggregate("checkTypes", -1, AggrCheckTypes) self.con.create_aggregate("mysum", 1, AggrSum) + self.con.create_aggregate("aggtxt", 1, AggrText) def tearDown(self): #self.cur.close() @@ -431,6 +450,15 @@ class AggregateTests(unittest.TestCase): val = cur.fetchone()[0] self.assertEqual(val, 60) + def CheckAggrText(self): + cur = self.con.cursor() + for txt in ["foo", "1\x002"]: + with self.subTest(txt=txt): + cur.execute("select aggtxt(?) from test", (txt,)) + val = cur.fetchone()[0] + self.assertEqual(val, txt) + + class AuthorizerTests(unittest.TestCase): @staticmethod def authorizer_cb(action, arg1, arg2, dbname, source): |