Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Lib/test/test_tcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,43 @@ def test_splitdict(self):
expected = {'a': (1, 2, 3), 'something': 'foo', 'status': ''}
self.assertEqual(splitdict(tcl, arg), expected)

def test_join(self):
join = tkinter._join
tcl = self.interp.tk
def unpack(s):
return tcl.call('lindex', s, 0)
def check(value):
self.assertEqual(unpack(join([value])), value)
self.assertEqual(unpack(join([value, 0])), value)
self.assertEqual(unpack(unpack(join([[value]]))), value)
self.assertEqual(unpack(unpack(join([[value, 0]]))), value)
self.assertEqual(unpack(unpack(join([[value], 0]))), value)
self.assertEqual(unpack(unpack(join([[value, 0], 0]))), value)
check('')
check('spam')
check('sp am')
check('sp\tam')
check('sp\nam')
check(' \t\n')
check('{spam}')
check('{sp am}')
check('"spam"')
check('"sp am"')
check('{"spam"}')
check('"{spam}"')
check('sp\\am')
check('"sp\\am"')
check('"{}" "{}"')
check('"\\')
check('"{')
check('"}')
check('\n\\')
check('\n{')
check('\n}')
check('\\\n')
check('{\n')
check('}\n')

def test_new_tcl_obj(self):
self.assertRaises(TypeError, _tkinter.Tcl_Obj)

Expand Down
5 changes: 4 additions & 1 deletion Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _stringify(value):
if isinstance(value, (list, tuple)):
if len(value) == 1:
value = _stringify(value[0])
if value[0] == '{':
if _magic_re.search(value):
value = '{%s}' % value
else:
value = '{%s}' % _join(value)
Expand All @@ -72,7 +72,10 @@ def _stringify(value):
elif _magic_re.search(value):
# add '\' before special characters and spaces
value = _magic_re.sub(r'\\\1', value)
value = value.replace('\n', r'\n')
value = _space_re.sub(r'\\\1', value)
if value[0] == '"':
value = '\\' + value
elif value[0] == '"' or _space_re.search(value):
value = '{%s}' % value
return value
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed passing lists and tuples of strings containing special characters
``"``, ``\``, ``{``, ``}`` and ``\n`` as options to :mod:`~tkinter.ttk`
widgets.