[Python-checkins] cpython (3.5): Issue #24580: Symbolic group references to open group in re patterns now are
serhiy.storchaka
python-checkins at python.org
Sat Jul 18 22:38:11 CEST 2015
https://hg.python.org/cpython/rev/361d7af9396e
changeset: 96949:361d7af9396e
branch: 3.5
parent: 96947:66a5f66b4049
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sat Jul 18 23:27:00 2015 +0300
summary:
Issue #24580: Symbolic group references to open group in re patterns now are
explicitly forbidden as well as numeric group references.
files:
Lib/sre_parse.py | 3 +++
Lib/test/test_re.py | 2 ++
Misc/NEWS | 3 +++
3 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -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 --git a/Lib/test/test_re.py b/Lib/test/test_re.py
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -224,6 +224,8 @@
self.checkPatternError('(?P<a>)(?P<a>)',
"redefinition of group name 'a' as group 2; "
"was group 1")
+ self.checkPatternError('(?P<a>(?P=a))',
+ "cannot refer to an open group", 10)
self.checkPatternError('(?Pxy)', 'unknown extension ?Px')
self.checkPatternError('(?P<a>)(?P=a', 'missing ), unterminated name', 11)
self.checkPatternError('(?P=', 'missing group name', 4)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,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.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list