mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
fixed #449964: sre.sub raises an exception if the template contains a
\g<x> group reference followed by a character escape (also restructured a few things on the way to fixing #449000)
This commit is contained in:
parent
ab3b0343b8
commit
59b68656f8
4 changed files with 30 additions and 21 deletions
12
Lib/sre.py
12
Lib/sre.py
|
@ -251,11 +251,13 @@ def _subn(pattern, template, text, count=0, sub=0):
|
|||
else:
|
||||
template = _compile_repl(template, pattern)
|
||||
literals = template[1]
|
||||
sub = 0 # temporarly disabled, see bug #449000
|
||||
if (sub and not count and pattern._isliteral() and
|
||||
len(literals) == 1 and literals[0]):
|
||||
# shortcut: both pattern and string are literals
|
||||
return string.replace(text, pattern.pattern, literals[0]), 0
|
||||
if sub and not count:
|
||||
literal = pattern._getliteral()
|
||||
if literal and "\\" in literal:
|
||||
literal = None # may contain untranslated escapes
|
||||
if literal is not None and len(literals) == 1 and literals[0]:
|
||||
# shortcut: both pattern and string are literals
|
||||
return string.replace(text, pattern.pattern, literals[0]), 0
|
||||
def filter(match, template=template):
|
||||
return sre_parse.expand_template(template, match)
|
||||
n = i = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue