diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2004-10-17 16:27:18 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2004-10-17 16:27:18 (GMT) |
commit | 6627a9670541f33ae55f6ba8df6b6ce7264c3f34 (patch) | |
tree | 7e39af74a2fe4eaa76bc2cb339481d8d9079276e /Lib/test/test_pep292.py | |
parent | 1338946c7bd0f6545d1dcde5d0bd62ff7a7db510 (diff) | |
download | cpython-6627a9670541f33ae55f6ba8df6b6ce7264c3f34.zip cpython-6627a9670541f33ae55f6ba8df6b6ce7264c3f34.tar.gz cpython-6627a9670541f33ae55f6ba8df6b6ce7264c3f34.tar.bz2 |
Invalid patterns to substitute and safe_substitute would crash since pattern
is not a local variable. Add a test case.
Diffstat (limited to 'Lib/test/test_pep292.py')
-rw-r--r-- | Lib/test/test_pep292.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_pep292.py b/Lib/test/test_pep292.py index f955774..19952e4 100644 --- a/Lib/test/test_pep292.py +++ b/Lib/test/test_pep292.py @@ -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\xffm', what=u'f\xfe\fed') |