mirror of
https://github.com/python/cpython.git
synced 2025-09-22 16:33:26 +00:00
bpo-47227: Suppress expression chaining for more RE parsing errors (GH-32333)
This commit is contained in:
parent
b09184bf05
commit
50872dbadc
2 changed files with 6 additions and 5 deletions
|
@ -335,7 +335,7 @@ def _class_escape(source, escape):
|
||||||
c = ord(unicodedata.lookup(charname))
|
c = ord(unicodedata.lookup(charname))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise source.error("undefined character name %r" % charname,
|
raise source.error("undefined character name %r" % charname,
|
||||||
len(charname) + len(r'\N{}'))
|
len(charname) + len(r'\N{}')) from None
|
||||||
return LITERAL, c
|
return LITERAL, c
|
||||||
elif c in OCTDIGITS:
|
elif c in OCTDIGITS:
|
||||||
# octal escape (up to three digits)
|
# octal escape (up to three digits)
|
||||||
|
@ -395,7 +395,7 @@ def _escape(source, escape, state):
|
||||||
c = ord(unicodedata.lookup(charname))
|
c = ord(unicodedata.lookup(charname))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise source.error("undefined character name %r" % charname,
|
raise source.error("undefined character name %r" % charname,
|
||||||
len(charname) + len(r'\N{}'))
|
len(charname) + len(r'\N{}')) from None
|
||||||
return LITERAL, c
|
return LITERAL, c
|
||||||
elif c == "0":
|
elif c == "0":
|
||||||
# octal escape
|
# octal escape
|
||||||
|
@ -1014,7 +1014,7 @@ def parse_template(source, state):
|
||||||
try:
|
try:
|
||||||
index = groupindex[name]
|
index = groupindex[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise IndexError("unknown group name %r" % name)
|
raise IndexError("unknown group name %r" % name) from None
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
index = int(name)
|
index = int(name)
|
||||||
|
@ -1053,7 +1053,7 @@ def parse_template(source, state):
|
||||||
this = chr(ESCAPES[this][1])
|
this = chr(ESCAPES[this][1])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if c in ASCIILETTERS:
|
if c in ASCIILETTERS:
|
||||||
raise s.error('bad escape %s' % this, len(this))
|
raise s.error('bad escape %s' % this, len(this)) from None
|
||||||
lappend(this)
|
lappend(this)
|
||||||
else:
|
else:
|
||||||
lappend(this)
|
lappend(this)
|
||||||
|
@ -1074,5 +1074,5 @@ def expand_template(template, match):
|
||||||
for index, group in groups:
|
for index, group in groups:
|
||||||
literals[index] = g(group) or empty
|
literals[index] = g(group) or empty
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise error("invalid group reference %d" % index)
|
raise error("invalid group reference %d" % index) from None
|
||||||
return empty.join(literals)
|
return empty.join(literals)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Suppress expression chaining for more :mod:`re` parsing errors.
|
Loading…
Add table
Add a link
Reference in a new issue