Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
60773392
Commit
60773392
authored
Apr 14, 2013
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#17341: Include name in re error message about invalid group name.
Patch by Jason Michalski.
parent
ff99e414
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
2 deletions
+19
-2
Lib/sre_parse.py
Lib/sre_parse.py
+4
-2
Lib/test/test_re.py
Lib/test/test_re.py
+11
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/sre_parse.py
View file @
60773392
...
...
@@ -549,7 +549,8 @@ def _parse(source, state):
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
=
""
...
...
@@ -563,7 +564,8 @@ def _parse(source, state):
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"
...
...
Lib/test/test_re.py
View file @
60773392
...
...
@@ -2,6 +2,7 @@ from test.test_support import verbose, run_unittest, import_module
from
test.test_support
import
precisionbigmemtest
,
_2G
,
cpython_only
import
re
from
re
import
Scanner
import
sre_constants
import
sys
import
string
import
traceback
...
...
@@ -886,6 +887,16 @@ class ReTests(unittest.TestCase):
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, '
\
?
f
oo'):
re.compile('(?P<?foo>)')
def run_re_tests():
from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
...
...
Misc/ACKS
View file @
60773392
...
...
@@ -674,6 +674,7 @@ Carl Meyer
Mike Meyer
Piotr Meyer
Steven Miale
Jason Michalski
Trent Mick
Tom Middleton
Stan Mihai
...
...
Misc/NEWS
View file @
60773392
...
...
@@ -25,6 +25,9 @@ Core and Builtins
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
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment