From 50872dbadcba1f52867b6f76050cd7b5d0aa1e18 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 6 Apr 2022 19:54:44 +0300 Subject: bpo-47227: Suppress expression chaining for more RE parsing errors (GH-32333) --- Lib/re/_parser.py | 10 +++++----- .../next/Library/2022-04-05-15-53-58.bpo-47227.1HWdp9.rst | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-04-05-15-53-58.bpo-47227.1HWdp9.rst diff --git a/Lib/re/_parser.py b/Lib/re/_parser.py index eca2ffc..f191f80 100644 --- a/Lib/re/_parser.py +++ b/Lib/re/_parser.py @@ -335,7 +335,7 @@ def _class_escape(source, escape): c = ord(unicodedata.lookup(charname)) except KeyError: raise source.error("undefined character name %r" % charname, - len(charname) + len(r'\N{}')) + len(charname) + len(r'\N{}')) from None return LITERAL, c elif c in OCTDIGITS: # octal escape (up to three digits) @@ -395,7 +395,7 @@ def _escape(source, escape, state): c = ord(unicodedata.lookup(charname)) except KeyError: raise source.error("undefined character name %r" % charname, - len(charname) + len(r'\N{}')) + len(charname) + len(r'\N{}')) from None return LITERAL, c elif c == "0": # octal escape @@ -1014,7 +1014,7 @@ def parse_template(source, state): try: index = groupindex[name] except KeyError: - raise IndexError("unknown group name %r" % name) + raise IndexError("unknown group name %r" % name) from None else: try: index = int(name) @@ -1053,7 +1053,7 @@ def parse_template(source, state): this = chr(ESCAPES[this][1]) except KeyError: 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) else: lappend(this) @@ -1074,5 +1074,5 @@ def expand_template(template, match): for index, group in groups: literals[index] = g(group) or empty except IndexError: - raise error("invalid group reference %d" % index) + raise error("invalid group reference %d" % index) from None return empty.join(literals) diff --git a/Misc/NEWS.d/next/Library/2022-04-05-15-53-58.bpo-47227.1HWdp9.rst b/Misc/NEWS.d/next/Library/2022-04-05-15-53-58.bpo-47227.1HWdp9.rst new file mode 100644 index 0000000..254d951 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-04-05-15-53-58.bpo-47227.1HWdp9.rst @@ -0,0 +1 @@ +Suppress expression chaining for more :mod:`re` parsing errors. -- cgit v0.12