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
6627a967
Commit
6627a967
authored
Oct 17, 2004
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Invalid patterns to substitute and safe_substitute would crash since pattern
is not a local variable. Add a test case.
parent
1338946c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
Lib/string.py
Lib/string.py
+4
-2
Lib/test/test_pep292.py
Lib/test/test_pep292.py
+12
-0
No files found.
Lib/string.py
View file @
6627a967
...
...
@@ -167,7 +167,8 @@ class Template:
return self.delimiter
if mo.group('invalid') is not None:
self._invalid(mo)
raise ValueError('Unrecognized named group in pattern', pattern)
raise ValueError('Unrecognized named group in pattern',
self.pattern)
return self.pattern.sub(convert, self.template)
def safe_substitute(self, *args, **kws):
...
...
@@ -199,7 +200,8 @@ class Template:
return self.delimiter
if mo.group('invalid') is not None:
self._invalid(mo)
raise ValueError('Unrecognized named group in pattern', pattern)
raise ValueError('Unrecognized named group in pattern',
self.pattern)
return self.pattern.sub(convert, self.template)
...
...
Lib/test/test_pep292.py
View file @
6627a967
...
...
@@ -113,6 +113,18 @@ class TestTemplate(unittest.TestCase):
s
=
MyPattern
(
'@bag.foo.who likes to eat a bag of @bag.what'
)
self
.
assertEqual
(
s
.
substitute
(
m
),
'tim likes to eat a bag of ham'
)
class
BadPattern
(
Template
):
pattern
=
r"""
(?P<badname>.*) |
(?P<escaped>@{2}) |
@(?P<named>[_a-z][._a-z0-9]*) |
@{(?P<braced>[_a-z][._a-z0-9]*)} |
(?P<invalid>@) |
"""
s
=
BadPattern
(
'@bag.foo.who likes to eat a bag of @bag.what'
)
self
.
assertRaises
(
ValueError
,
s
.
substitute
,
{})
self
.
assertRaises
(
ValueError
,
s
.
safe_substitute
,
{})
def
test_unicode_values
(
self
):
s
=
Template
(
'$who likes $what'
)
d
=
dict
(
who
=
u't
\
xff
m'
,
what
=
u'f
\
xfe
\
f
ed'
)
...
...
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