summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/TokenParser/AutoEscape.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2013-08-01 23:43:20 -0400
committerczaks <marcin@6irc.net>2013-08-01 23:43:20 -0400
commit1ed45ebe9e39724ec70098abfcd267d8ac478511 (patch)
treeda133b7426dedaf0785f64be752aa0437de7e80a /inc/lib/Twig/TokenParser/AutoEscape.php
parentdc84ccc6a8e0b6fd3fc626eb1f321e4cf2d05511 (diff)
parent40ab2e0c1728fab613bc16a19ab8fcb3fa78c1d4 (diff)
Merge branch 'master' of https://github.com/savetheinternet/Tinyboard
Conflicts: stylesheets/dark.css stylesheets/futaba+vichan.css stylesheets/miku.css stylesheets/stripes.css stylesheets/testorange.css stylesheets/wasabi.css
Diffstat (limited to 'inc/lib/Twig/TokenParser/AutoEscape.php')
-rw-r--r--inc/lib/Twig/TokenParser/AutoEscape.php36
1 files changed, 24 insertions, 12 deletions
diff --git a/inc/lib/Twig/TokenParser/AutoEscape.php b/inc/lib/Twig/TokenParser/AutoEscape.php
index 3b4b96e3..27560288 100644
--- a/inc/lib/Twig/TokenParser/AutoEscape.php
+++ b/inc/lib/Twig/TokenParser/AutoEscape.php
@@ -39,23 +39,35 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
- $value = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
- if (!in_array($value, array('true', 'false'))) {
- throw new Twig_Error_Syntax("Autoescape value must be 'true' or 'false'", $lineno);
- }
- $value = 'true' === $value ? 'html' : false;
+ $stream = $this->parser->getStream();
+
+ if ($stream->test(Twig_Token::BLOCK_END_TYPE)) {
+ $value = 'html';
+ } else {
+ $expr = $this->parser->getExpressionParser()->parseExpression();
+ if (!$expr instanceof Twig_Node_Expression_Constant) {
+ throw new Twig_Error_Syntax('An escaping strategy must be a string or a Boolean.', $stream->getCurrent()->getLine(), $stream->getFilename());
+ }
+ $value = $expr->getAttribute('value');
- if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE)) {
- if (false === $value) {
- throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $lineno);
+ $compat = true === $value || false === $value;
+
+ if (true === $value) {
+ $value = 'html';
}
- $value = $this->parser->getStream()->next()->getValue();
+ if ($compat && $stream->test(Twig_Token::NAME_TYPE)) {
+ if (false === $value) {
+ throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getFilename());
+ }
+
+ $value = $stream->next()->getValue();
+ }
}
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
- $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+ $stream->expect(Twig_Token::BLOCK_END_TYPE);
return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag());
}
@@ -68,7 +80,7 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser
/**
* Gets the tag name associated with this token parser.
*
- * @param string The tag name
+ * @return string The tag name
*/
public function getTag()
{