summaryrefslogtreecommitdiffstats
path: root/Lib/lib-tk/Tkinter.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-06-30 10:34:56 (GMT)
committerGitHub <noreply@github.com>2018-06-30 10:34:56 (GMT)
commit9b84cc8771f52e9340ea5b676da9a15359c723b6 (patch)
treecfaddc9049f7ac21be46d5b4c996314afd426786 /Lib/lib-tk/Tkinter.py
parent0464de0f9a226cfa32b803e0326c12b2432aba26 (diff)
downloadcpython-9b84cc8771f52e9340ea5b676da9a15359c723b6.zip
cpython-9b84cc8771f52e9340ea5b676da9a15359c723b6.tar.gz
cpython-9b84cc8771f52e9340ea5b676da9a15359c723b6.tar.bz2
[2.7] bpo-33974: Fix passing special characters to ttk widgets. (GH-7986) (GH-8021)
Fix passing lists and tuples of strings containing special characters '"', '\\', '{', '}' and '\n' as options to tkinter.ttk widgets. (cherry picked from commit 5bb5bbfca847524bab5f2368bdb48eedf5dba74f)
Diffstat (limited to 'Lib/lib-tk/Tkinter.py')
-rw-r--r--Lib/lib-tk/Tkinter.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py
index f46642f..2f3a3f1 100644
--- a/Lib/lib-tk/Tkinter.py
+++ b/Lib/lib-tk/Tkinter.py
@@ -71,7 +71,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)
@@ -85,7 +85,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