summaryrefslogtreecommitdiff
path: root/Lib/test/test_string.py
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2017-10-13 16:02:23 +0900
committerGitHub <noreply@github.com>2017-10-13 16:02:23 +0900
commitb22273ec5d1992b0cbe078b887427ae9977dfb78 (patch)
tree513406f0548f326404ff00e67f6a7e9093c78dd2 /Lib/test/test_string.py
parent925510449984399cf58711843ddfe2e8007c3878 (diff)
downloadcpython-git-b22273ec5d1992b0cbe078b887427ae9977dfb78.tar.gz
bpo-31672: Fix string.Template accidentally matched non-ASCII identifiers (GH-3872)
Pattern `[a-z]` with `IGNORECASE` flag can match to some non-ASCII characters. Straightforward solution for this is using `IGNORECASE | ASCII` flag. But users may subclass `Template` and override only `idpattern`. So we want to avoid changing `Template.flags`. So this commit uses local flag `-i` for `idpattern` and change `[a-z]` to `[a-zA-Z]`.
Diffstat (limited to 'Lib/test/test_string.py')
-rw-r--r--Lib/test/test_string.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py
index 6e241ac72a..3480459c28 100644
--- a/Lib/test/test_string.py
+++ b/Lib/test/test_string.py
@@ -270,6 +270,12 @@ class TestTemplate(unittest.TestCase):
raises(ValueError, s.substitute, dict(who='tim'))
s = Template('$who likes $100')
raises(ValueError, s.substitute, dict(who='tim'))
+ # Template.idpattern should match to only ASCII characters.
+ # https://bugs.python.org/issue31672
+ s = Template("$who likes $\u0131") # (DOTLESS I)
+ raises(ValueError, s.substitute, dict(who='tim'))
+ s = Template("$who likes $\u0130") # (LATIN CAPITAL LETTER I WITH DOT ABOVE)
+ raises(ValueError, s.substitute, dict(who='tim'))
def test_idpattern_override(self):
class PathPattern(Template):