summaryrefslogtreecommitdiffstats
path: root/Lib/sre.py
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2001-09-18 20:55:24 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2001-09-18 20:55:24 (GMT)
commit59b68656f846973840953220c4780f3558b59fb8 (patch)
tree6a91ff46e00681f594aa3c9280d268627d009cc5 /Lib/sre.py
parentab3b0343b89b4683148dadaf89728ee1198ebee5 (diff)
downloadcpython-59b68656f846973840953220c4780f3558b59fb8.zip
cpython-59b68656f846973840953220c4780f3558b59fb8.tar.gz
cpython-59b68656f846973840953220c4780f3558b59fb8.tar.bz2
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)
Diffstat (limited to 'Lib/sre.py')
-rw-r--r--Lib/sre.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/sre.py b/Lib/sre.py
index a87870e..7a640f9 100644
--- a/Lib/sre.py
+++ b/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