summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-07-18 20:37:31 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-07-18 20:37:31 (GMT)
commit498b5e98e9aaf5057d73cda1940b9c2d93305455 (patch)
tree05cc0dcbec54846266506038a8052e1a9b5b66a7
parent44a5cd654d8f617df72936167c5f57141b8e86bb (diff)
parent485407ce1e4dc3b2005bc1c72ce6020c28f90030 (diff)
downloadcpython-498b5e98e9aaf5057d73cda1940b9c2d93305455.zip
cpython-498b5e98e9aaf5057d73cda1940b9c2d93305455.tar.gz
cpython-498b5e98e9aaf5057d73cda1940b9c2d93305455.tar.bz2
Issue #24580: Symbolic group references to open group in re patterns now are
explicitly forbidden as well as numeric group references.
-rw-r--r--Lib/sre_parse.py3
-rw-r--r--Lib/test/test_re.py2
-rw-r--r--Misc/NEWS3
3 files changed, 8 insertions, 0 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index c0f539d..67f84e9 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 5b71612..7a74141 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -224,6 +224,8 @@ class ReTests(unittest.TestCase):
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
index db0e776..906ca57 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -41,6 +41,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.