diff options
author | INADA Naoki <methane@users.noreply.github.com> | 2017-10-14 05:21:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-14 05:21:59 (GMT) |
commit | 7060380d577690a40ebc201c0725076349e977cd (patch) | |
tree | 792fe8b9f5a18ff8680f13d03ae27b0544e0fce1 /Doc/library | |
parent | 6234e9068332f61f935cf13fa5b1a924a99c28b2 (diff) | |
download | cpython-7060380d577690a40ebc201c0725076349e977cd.zip cpython-7060380d577690a40ebc201c0725076349e977cd.tar.gz cpython-7060380d577690a40ebc201c0725076349e977cd.tar.bz2 |
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]`.
(cherry picked from commit b22273ec5d1992b0cbe078b887427ae9977dfb78)
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/string.rst | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst index a0977b6..7a9fcc3 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -746,8 +746,18 @@ to parse template strings. To do this, you can override these class attributes: * *idpattern* -- This is the regular expression describing the pattern for non-braced placeholders (the braces will be added automatically as - appropriate). The default value is the regular expression - ``[_a-z][_a-z0-9]*``. + appropriate). The default value is the regular expression + ``(?-i:[_a-zA-Z][_a-zA-Z0-9]*)``. + + .. note:: + + Since default *flags* is ``re.IGNORECASE``, pattern ``[a-z]`` can match + with some non-ASCII characters. That's why we use local ``-i`` flag here. + + While *flags* is kept to ``re.IGNORECASE`` for backward compatibility, + you can override it to ``0`` or ``re.IGNORECASE | re.ASCII`` when + subclassing. + * *flags* -- The regular expression flags that will be applied when compiling the regular expression used for recognizing substitutions. The default value |