mirror of
https://github.com/python/cpython.git
synced 2025-12-09 10:37:17 +00:00
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]`.
This commit is contained in:
parent
9255104499
commit
b22273ec5d
4 changed files with 24 additions and 3 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue