Revision 1852
Added by darkviper over 11 years ago
AutoEscape.php | ||
---|---|---|
39 | 39 |
public function parse(Twig_Token $token) |
40 | 40 |
{ |
41 | 41 |
$lineno = $token->getLine(); |
42 |
$value = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(); |
|
43 |
if (!in_array($value, array('true', 'false'))) { |
|
44 |
throw new Twig_Error_Syntax("Autoescape value must be 'true' or 'false'", $lineno); |
|
45 |
} |
|
46 |
$value = 'true' === $value ? 'html' : false; |
|
42 |
$stream = $this->parser->getStream(); |
|
47 | 43 |
|
48 |
if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE)) { |
|
49 |
if (false === $value) { |
|
50 |
throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $lineno); |
|
44 |
if ($stream->test(Twig_Token::BLOCK_END_TYPE)) { |
|
45 |
$value = 'html'; |
|
46 |
} else { |
|
47 |
$expr = $this->parser->getExpressionParser()->parseExpression(); |
|
48 |
if (!$expr instanceof Twig_Node_Expression_Constant) { |
|
49 |
throw new Twig_Error_Syntax('An escaping strategy must be a string or a Boolean.', $stream->getCurrent()->getLine(), $stream->getFilename()); |
|
51 | 50 |
} |
51 |
$value = $expr->getAttribute('value'); |
|
52 | 52 |
|
53 |
$value = $this->parser->getStream()->next()->getValue(); |
|
53 |
$compat = true === $value || false === $value; |
|
54 |
|
|
55 |
if (true === $value) { |
|
56 |
$value = 'html'; |
|
57 |
} |
|
58 |
|
|
59 |
if ($compat && $stream->test(Twig_Token::NAME_TYPE)) { |
|
60 |
if (false === $value) { |
|
61 |
throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getFilename()); |
|
62 |
} |
|
63 |
|
|
64 |
$value = $stream->next()->getValue(); |
|
65 |
} |
|
54 | 66 |
} |
55 | 67 |
|
56 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
|
68 |
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
|
57 | 69 |
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); |
58 |
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
|
70 |
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
|
59 | 71 |
|
60 | 72 |
return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag()); |
61 | 73 |
} |
Also available in: Unified diff
updated Twig template engine to stable version 1.11.1 step2