mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
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:
parent
fc297b4ba4
commit
c38e2f64d0
4 changed files with 68 additions and 7 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue