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

Now the null character is always represented as \xc0\x80 for
Tcl_NewStringObj().
(cherry picked from commit c38e2f64d0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-06-24 11:45:45 +02:00 committed by GitHub
parent 206028dba9
commit 732c00550f
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 @@ def test_info_patchlevel(self):
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):