mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-111089: PyUnicode_AsUTF8() now raises on embedded NUL (#111091)
* PyUnicode_AsUTF8() now raises an exception if the string contains embedded null characters. * Update related C API tests (test_capi.test_unicode). * type_new_set_doc() uses PyUnicode_AsUTF8AndSize() to silently truncate doc containing null bytes. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
59ea0f523e
commit
d731579bfb
8 changed files with 49 additions and 25 deletions
|
@ -882,7 +882,10 @@ class CAPITest(unittest.TestCase):
|
|||
self.assertEqual(unicode_asutf8('abc', 4), b'abc\0')
|
||||
self.assertEqual(unicode_asutf8('абв', 7), b'\xd0\xb0\xd0\xb1\xd0\xb2\0')
|
||||
self.assertEqual(unicode_asutf8('\U0001f600', 5), b'\xf0\x9f\x98\x80\0')
|
||||
self.assertEqual(unicode_asutf8('abc\0def', 8), b'abc\0def\0')
|
||||
|
||||
# disallow embedded null characters
|
||||
self.assertRaises(ValueError, unicode_asutf8, 'abc\0', 0)
|
||||
self.assertRaises(ValueError, unicode_asutf8, 'abc\0def', 0)
|
||||
|
||||
self.assertRaises(UnicodeEncodeError, unicode_asutf8, '\ud8ff', 0)
|
||||
self.assertRaises(TypeError, unicode_asutf8, b'abc', 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue