From: Serhiy Storchaka Date: Sat, 18 Jul 2015 20:27:00 +0000 (+0300) Subject: Issue #24580: Symbolic group references to open group in re patterns now are X-Git-Tag: v3.5.0b4~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=485407ce1e4dc3b2005bc1c72ce6020c28f90030;p=python Issue #24580: Symbolic group references to open group in re patterns now are explicitly forbidden as well as numeric group references. --- diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index c0f539dd93..67f84e940f 100644 --- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -675,6 +675,9 @@ def _parse(source, state): if gid is None: msg = "unknown group name %r" % name 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) subpatternappend((GROUPREF, gid)) continue diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 5b716125f9..7a741416b4 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -224,6 +224,8 @@ class ReTests(unittest.TestCase): self.checkPatternError('(?P)(?P)', "redefinition of group name 'a' as group 2; " "was group 1") + self.checkPatternError('(?P(?P=a))', + "cannot refer to an open group", 10) self.checkPatternError('(?Pxy)', 'unknown extension ?Px') self.checkPatternError('(?P)(?P=a', 'missing ), unterminated name', 11) self.checkPatternError('(?P=', 'missing group name', 4) diff --git a/Misc/NEWS b/Misc/NEWS index b400a91211..834ce388fe 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -19,6 +19,9 @@ Core and Builtins 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 #24631: Fixed regression in the timeit module with multiline setup.