Kaydet (Commit) 498b5e98 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Issue #24580: Symbolic group references to open group in re patterns now are

explicitly forbidden as well as numeric group references.
...@@ -675,6 +675,9 @@ def _parse(source, state): ...@@ -675,6 +675,9 @@ def _parse(source, state):
if gid is None: if gid is None:
msg = "unknown group name %r" % name msg = "unknown group name %r" % name
raise source.error(msg, len(name) + 1) raise source.error(msg, len(name) + 1)
if not state.checkgroup(gid):
raise source.error("cannot refer to an open group",
len(name) + 1)
state.checklookbehindgroup(gid, source) state.checklookbehindgroup(gid, source)
subpatternappend((GROUPREF, gid)) subpatternappend((GROUPREF, gid))
continue continue
......
...@@ -224,6 +224,8 @@ class ReTests(unittest.TestCase): ...@@ -224,6 +224,8 @@ class ReTests(unittest.TestCase):
self.checkPatternError('(?P<a>)(?P<a>)', self.checkPatternError('(?P<a>)(?P<a>)',
"redefinition of group name 'a' as group 2; " "redefinition of group name 'a' as group 2; "
"was group 1") "was group 1")
self.checkPatternError('(?P<a>(?P=a))',
"cannot refer to an open group", 10)
self.checkPatternError('(?Pxy)', 'unknown extension ?Px') self.checkPatternError('(?Pxy)', 'unknown extension ?Px')
self.checkPatternError('(?P<a>)(?P=a', 'missing ), unterminated name', 11) self.checkPatternError('(?P<a>)(?P=a', 'missing ), unterminated name', 11)
self.checkPatternError('(?P=', 'missing group name', 4) self.checkPatternError('(?P=', 'missing group name', 4)
......
...@@ -41,6 +41,9 @@ Core and Builtins ...@@ -41,6 +41,9 @@ Core and Builtins
Library Library
------- -------
- Issue #24580: Symbolic group references to open group in re patterns now are
explicitly forbidden as well as numeric group references.
- Issue #24206: Fixed __eq__ and __ne__ methods of inspect classes. - Issue #24206: Fixed __eq__ and __ne__ methods of inspect classes.
- Issue #24631: Fixed regression in the timeit module with multiline setup. - Issue #24631: Fixed regression in the timeit module with multiline setup.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment