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

@ -73,6 +73,18 @@ class TclTest(unittest.TestCase):
tcl.call('set','a','1')
self.assertEqual(tcl.call('set','a'),'1')
def test_call_passing_null(self):
tcl = self.interp
tcl.call('set', 'a', 'a\0b') # ASCII-only
self.assertEqual(tcl.getvar('a'), 'a\x00b')
self.assertEqual(tcl.call('set', 'a'), 'a\x00b')
self.assertEqual(tcl.eval('set a'), 'a\x00b')
tcl.call('set', 'a', '\u20ac\0') # non-ASCII
self.assertEqual(tcl.getvar('a'), '\u20ac\x00')
self.assertEqual(tcl.call('set', 'a'), '\u20ac\x00')
self.assertEqual(tcl.eval('set a'), '\u20ac\x00')
def testCallException(self):
tcl = self.interp
self.assertRaises(TclError,tcl.call,'set','a')
@ -98,6 +110,18 @@ class TclTest(unittest.TestCase):
tcl.setvar('a','1')
self.assertEqual(tcl.eval('set a'),'1')
def test_setvar_passing_null(self):
tcl = self.interp
tcl.setvar('a', 'a\0b') # ASCII-only
self.assertEqual(tcl.getvar('a'), 'a\x00b')
self.assertEqual(tcl.call('set', 'a'), 'a\x00b')
self.assertEqual(tcl.eval('set a'), 'a\x00b')
tcl.setvar('a', '\u20ac\0') # non-ASCII
self.assertEqual(tcl.getvar('a'), '\u20ac\x00')
self.assertEqual(tcl.call('set', 'a'), '\u20ac\x00')
self.assertEqual(tcl.eval('set a'), '\u20ac\x00')
def testSetVarArray(self):
tcl = self.interp
tcl.setvar('a(1)','1')