changeset: 96950:4d3557500019 parent: 96948:adc9869c6d0d parent: 96949:361d7af9396e user: Serhiy Storchaka date: Sat Jul 18 23:37:31 2015 +0300 files: Misc/NEWS description: Issue #24580: Symbolic group references to open group in re patterns now are explicitly forbidden as well as numeric group references. diff -r adc9869c6d0d -r 4d3557500019 Lib/sre_parse.py --- a/Lib/sre_parse.py Sat Jul 18 23:21:16 2015 +0300 +++ b/Lib/sre_parse.py Sat Jul 18 23:37:31 2015 +0300 @@ -675,6 +675,9 @@ 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 -r adc9869c6d0d -r 4d3557500019 Lib/test/test_re.py --- a/Lib/test/test_re.py Sat Jul 18 23:21:16 2015 +0300 +++ b/Lib/test/test_re.py Sat Jul 18 23:37:31 2015 +0300 @@ -224,6 +224,8 @@ 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 -r adc9869c6d0d -r 4d3557500019 Misc/NEWS --- a/Misc/NEWS Sat Jul 18 23:21:16 2015 +0300 +++ b/Misc/NEWS Sat Jul 18 23:37:31 2015 +0300 @@ -41,6 +41,9 @@ 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.