summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2018-03-08 14:45:34 +0100
committerMarcel Hellkamp <marc@gsites.de>2018-10-25 15:49:19 +0200
commite76a736ae57a615d7c64e143a352b3cf66494836 (patch)
tree3b36f22e22400e84adf63fca32ae9b2434c3ba03
parent5aeb2562de4c8133dcba8a8cf49b6ec90cd15d1f (diff)
downloadbottle-e76a736ae57a615d7c64e143a352b3cf66494836.tar.gz
fix: STPL end keyword breaks when not on a separate line
This fix allows templates with the 'end' keyword in the same line as other code. %if 1: % some code; end Multiple 'end's in the same line to close multiple blocks whould also work now.
-rwxr-xr-xbottle.py12
-rwxr-xr-xtest/test_stpl.py10
2 files changed, 17 insertions, 5 deletions
diff --git a/bottle.py b/bottle.py
index 8e446a8..0f79a71 100755
--- a/bottle.py
+++ b/bottle.py
@@ -4010,7 +4010,6 @@ class SimpleTemplate(BaseTemplate):
class StplSyntaxError(TemplateError):
-
pass
@@ -4152,15 +4151,18 @@ class StplParser(object):
self.paren_depth -= 1
code_line += _pc
elif _blk1: # Start-block keyword (if/for/while/def/try/...)
- code_line, self.indent_mod = _blk1, -1
+ code_line = _blk1
self.indent += 1
+ self.indent_mod -= 1
elif _blk2: # Continue-block keyword (else/elif/except/...)
- code_line, self.indent_mod = _blk2, -1
- elif _end: # The non-standard 'end'-keyword (ends a block)
- self.indent -= 1
+ code_line = _blk2
+ self.indent_mod -= 1
elif _cend: # The end-code-block template token (usually '%>')
if multiline: multiline = False
else: code_line += _cend
+ elif _end:
+ self.indent -= 1
+ self.indent_mod += 1
else: # \n
self.write_code(code_line.strip(), comment)
self.lineno += 1
diff --git a/test/test_stpl.py b/test/test_stpl.py
index 32468af..ab39b27 100755
--- a/test/test_stpl.py
+++ b/test/test_stpl.py
@@ -356,3 +356,13 @@ class TestSTPLDir(unittest.TestCase):
''', result='''
[1, 3, 5]
''')
+
+
+ def test_end_keyword_on_same_line(self):
+ self.assertRenders('''
+ % if 1:
+ % 1; end
+ foo
+ ''', '''
+ foo
+ ''')