mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 11:56:50 +00:00
fixed error handling for if tag when a syntax error occurs within a subparse process (closes #131)
This commit is contained in:
committed by
Fabien Potencier
parent
f7febc0c2c
commit
1230c210dc
@@ -5,6 +5,7 @@ Backward incompatibilities:
|
||||
* the odd and even filters are now tests:
|
||||
{{ foo|odd }} must now be written {{ foo is odd }}
|
||||
|
||||
* fixed error handling for if tag when a syntax error occurs within a subparse process
|
||||
* added a way to implement custom logic for resolving token parsers given a tag name
|
||||
* fixed js escaper to be stricter (now uses a whilelist-based js escaper)
|
||||
* added a "constant" filter
|
||||
|
||||
+17
-22
@@ -29,31 +29,26 @@ class Twig_TokenParser_If extends Twig_TokenParser
|
||||
|
||||
$end = false;
|
||||
while (!$end) {
|
||||
try
|
||||
{
|
||||
switch ($this->parser->getStream()->next()->getValue()) {
|
||||
case 'else':
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$else = $this->parser->subparse(array($this, 'decideIfEnd'));
|
||||
break;
|
||||
switch ($this->parser->getStream()->next()->getValue()) {
|
||||
case 'else':
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$else = $this->parser->subparse(array($this, 'decideIfEnd'));
|
||||
break;
|
||||
|
||||
case 'elseif':
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideIfFork'));
|
||||
$tests[] = $expr;
|
||||
$tests[] = $body;
|
||||
break;
|
||||
case 'elseif':
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideIfFork'));
|
||||
$tests[] = $expr;
|
||||
$tests[] = $body;
|
||||
break;
|
||||
|
||||
case 'endif':
|
||||
$end = true;
|
||||
break;
|
||||
case 'endif':
|
||||
$end = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Twig_SyntaxError('', -1);
|
||||
}
|
||||
} catch (Twig_SyntaxError $e) {
|
||||
throw new Twig_SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), -1);
|
||||
default:
|
||||
throw new Twig_SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user