Skip to content

Commit

Permalink
Throw a exception when no enddefer is found.
Browse files Browse the repository at this point in the history
No support for a expression like blocks since this will make the other arguments to hard to parse.
  • Loading branch information
boekkooi committed Jul 24, 2014
1 parent 8f90d5c commit 2014c33
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Twig/TokenParser/Defer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ protected function bodyParse(Twig_TokenStream $stream, $name, $lineno)
}
}
} else {
$body = new Twig_Node(
array(
new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno),
)
throw new Twig_Error_Syntax(
"Expected enddefer for defer '$name'",
$stream->getCurrent()->getLine(),
$stream->getFilename()
);
}
$stream->expect(Twig_Token::BLOCK_END_TYPE);
Expand Down
16 changes: 15 additions & 1 deletion tests/Twig/TokenParser/DeferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,21 @@ public function testCompile($source, \Twig_Node $bodyExpected, \Twig_Node $block

/**
* @expectedException \Twig_Error_Syntax
* @expectedExceptionMessage Expected enddefer for defer 'def
* @expectedExceptionMessage Expected enddefer for defer 'def_jsx'
*/
public function testNoEndBlock()
{
$env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
$env->addTokenParser(new Defer('def_'));
$stream = $env->tokenize('{% defer js "x" "foo" %}');
$parser = new \Twig_Parser($env);

$parser->parse($stream);
}

/**
* @expectedException \Twig_Error_Syntax
* @expectedExceptionMessage Expected enddefer for defer 'def_js0' (but css given)
*/
public function testInvalidEndBlockName()
{
Expand Down

0 comments on commit 2014c33

Please sign in to comment.