Skip to content

Commit

Permalink
Disallow garbage after #end blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jun 2, 2016
1 parent 8f0534a commit 8144daa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Cheetah/legacy_parser.py
Expand Up @@ -877,9 +877,11 @@ def eatEndDirective(self):
break
if not directiveName:
raise ParseError(self, msg='Invalid end directive')
self.advance(len(directiveName))

endOfFirstLinePos = self.findEOL()
self.getExpression() # eat in any extra comment-like crap
if self.getExpression().strip():
raise ParseError(self, 'Invalid garbage after #end directive')
self._eatRestOfDirectiveTag(isLineClearToStartToken, endOfFirstLinePos)
assert directiveName in CLOSABLE_DIRECTIVES
self.popFromOpenDirectivesStack(directiveName)
Expand Down
18 changes: 18 additions & 0 deletions tests/Parser_test.py
Expand Up @@ -579,3 +579,21 @@ def test_errors_on_blinged_kwarg():
compile_to_class(
'$foo($bar=$baz)'
)


def test_errors_garbage_after_end_directive():
with assert_raises_exactly(
ParseError,
'\n\n'
'Invalid garbage after #end directive\n'
'Line 2, column 15\n\n'
'Line|Cheetah Code\n'
'----|-------------------------------------------------------------\n'
'1 |#block foo\n'
'2 |#end block foo\n'
' ^\n'
):
compile_to_class(
'#block foo\n'
'#end block foo\n'
)
6 changes: 3 additions & 3 deletions tests/SyntaxAndOutput_test.py
Expand Up @@ -970,10 +970,10 @@ def test5(self):
outer
#block innerNest
inner
#end block innerNest
#end block outerNest
#end block
#end block
---
#end block testBlock
#end block
""",
"this is a test block\nouter\ninner\n---\n")

Expand Down

0 comments on commit 8144daa

Please sign in to comment.