8000 bpo-44822: Don't truncate `str`s with embedded NULL chars returned by `sqlite3` UDF callbacks by erlend-aasland · Pull Request #27588 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44822: Don't truncate strs with embedded NULL chars returned by sqlite3 UDF callbacks #27588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
Erlend E. Aasland committed Aug 4, 2021
commit 73639f12ed432562164f99a2f02182f84af794c0
9 changes: 9 additions & 0 deletions Lib/sqlite3/test/userfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def wrapper(self, *args, **kwargs):

def func_returntext():
return "foo"
def func_returntextwithnull():
return "1\x002"
def func_returnunicode():
return "bar"
def func_returnint():
Expand Down Expand Up @@ -168,6 +170,7 @@ 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)
Expand Down Expand Up @@ -211,6 +214,12 @@ def test_func_return_text(self):
self.assertEqual(type(val), str)
self.assertEqual(val, "foo")

def test_func_return_text_with_null_char(self):
cur = self.con.cursor()
res = cur.execute("select returntextwithnull()").fetchone()[0]
self.assertEqual(type(res), str)
self.assertEqual(res, "1\x002")

def test_func_return_unicode(self):
cur = self.con.cursor()
cur.execute("select returnunicode()")
Expand Down
0