if not name:
raise error("missing group name")
if not isname(name):
- raise error, "bad character in group name"
+ raise error("bad character in group name %r" %
+ name)
elif sourcematch("="):
# named backreference
name = ""
if not name:
raise error("missing group name")
if not isname(name):
- raise error, "bad character in group name"
+ raise error("bad character in backref group name "
+ "%r" % name)
gid = state.groupdict.get(name)
if gid is None:
raise error, "unknown group name"
from test.test_support import precisionbigmemtest, _2G, cpython_only
import re
from re import Scanner
+import sre_constants
import sys
import string
import traceback
self.assertRaises(OverflowError, re.compile, r".{,%d}" % MAXREPEAT)
self.assertRaises(OverflowError, re.compile, r".{%d,}?" % MAXREPEAT)
+ def test_backref_group_name_in_exception(self):
+ # Issue 17341: Poor error message when compiling invalid regex
+ with self.assertRaisesRegexp(sre_constants.error, '<foo>'):
+ re.compile('(?P=<foo>)')
+
+ def test_group_name_in_exception(self):
+ # Issue 17341: Poor error message when compiling invalid regex
+ with self.assertRaisesRegexp(sre_constants.error, '\?foo'):
+ re.compile('(?P<?foo>)')
+
def run_re_tests():
from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
Library
-------
+- Issue #17341: Include the invalid name in the error messages from re about
+ invalid group names.
+
- Issue #17016: Get rid of possible pointer wraparounds and integer overflows
in the re module. Patch by Nickolai Zeldovich.