diff options
author | Marcel Hellkamp <marc@gsites.de> | 2014-03-06 16:33:51 +0100 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2014-03-06 16:33:51 +0100 |
commit | 4d06a7bbb2cb877274fea3d462513884207f162a (patch) | |
tree | 6611af78b5a80d70203de0d924e3f8b52560c670 | |
parent | d7780fd5d5c2baeb0152864138adbbdfcf83e6e4 (diff) | |
download | bottle-4d06a7bbb2cb877274fea3d462513884207f162a.tar.gz |
fix #595: If expressions broken in STPL after upgrading
Fixed an error where everything before a block keyword (if/for/...) was
removed by the template parser. Example::
% m = 'a' if True else 'b'
was translated to::
if True else 'b'
insead of::
m = 'a' if True else 'b'
-rw-r--r-- | bottle.py | 3 | ||||
-rwxr-xr-x | test/test_stpl.py | 6 |
2 files changed, 9 insertions, 0 deletions
@@ -3486,6 +3486,9 @@ class StplParser(object): code_line += self.source[self.offset:self.offset+m.start()] self.offset += m.end() _str, _com, _blk1, _blk2, _end, _cend, _nl = m.groups() + if code_line and (_blk1 or _blk2): # a if b else c + code_line += _blk1 or _blk2 + continue if _str: # Python string code_line += _str elif _com: # Python comment (up to EOL) diff --git a/test/test_stpl.py b/test/test_stpl.py index 982d1b9..4c38f07 100755 --- a/test/test_stpl.py +++ b/test/test_stpl.py @@ -250,6 +250,12 @@ class TestSimpleTemplate(unittest.TestCase): def test_bug_no_whitespace_before_stmt(self): self.assertRenders('\n{{var}}', '\nx', var='x') + def test_bug_block_keywords_eat_prefixed_code(self): + ''' #595: Everything before an 'if' statement is removed, resulting in + SyntaxError. ''' + tpl = "% m = 'x' if True else 'y'\n{{m}}" + self.assertRenders(tpl, 'x') + class TestSTPLDir(unittest.TestCase): def fix_ident(self, string): |