gh-119614: Fix truncation of strings with embedded null characters in Tkinter (GH-120909)

Now the null character is always represented as \xc0\x80 for
Tcl_NewStringObj().
This commit is contained in:
Serhiy Storchaka 2024-06-24 12:17:25 +03:00 committed by GitHub
parent fc297b4ba4
commit c38e2f64d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 68 additions and 7 deletions

View file

@ -476,6 +476,15 @@ class MiscTest(AbstractTkTest, unittest.TestCase):
self.assertEqual(vi.micro, 0)
self.assertTrue(str(vi).startswith(f'{vi.major}.{vi.minor}'))
def test_embedded_null(self):
widget = tkinter.Entry(self.root)
widget.insert(0, 'abc\0def') # ASCII-only
widget.selection_range(0, 'end')
self.assertEqual(widget.selection_get(), 'abc\x00def')
widget.insert(0, '\u20ac\0') # non-ASCII
widget.selection_range(0, 'end')
self.assertEqual(widget.selection_get(), '\u20ac\0abc\x00def')
class WmTest(AbstractTkTest, unittest.TestCase):