{
$this->statusStack[] = $node->getValue();
}
- elseif ($node instanceof Twig_Node_Print && true === $this->needEscaping($env))
+ elseif ($node instanceof Twig_Node_Print)
{
- return $this->escapeNode($node, $env);
+ return $this->escapeNode($node, $env, $this->needEscaping($env));
}
elseif ($node instanceof Twig_Node_Block)
{
return $node;
}
- protected function escapeNode(Twig_Node $node, Twig_Environment $env)
+ protected function escapeNode(Twig_Node $node, Twig_Environment $env, $type)
{
+ if (false === $type)
+ {
+ return $node;
+ }
+
$expression = $node instanceof Twig_Node_Print ? $node->getExpression() : $node;
if ($expression instanceof Twig_Node_Expression_Filter)
{
foreach ($filter[1] as $j => $argument)
{
- $filters[$i][1][$j] = $this->escapeNode($argument, $env);
+ $filters[$i][1][$j] = $this->escapeNode($argument, $env, $type);
}
}
$expression->setFilters($filters);
- $expression->prependFilter($this->getEscaperFilter());
+ $expression->prependFilter($this->getEscaperFilter($type));
return $node;
}
elseif ($node instanceof Twig_Node_Print)
{
return new Twig_Node_Print(
- new Twig_Node_Expression_Filter($expression, array($this->getEscaperFilter()), $node->getLine())
+ new Twig_Node_Expression_Filter($expression, array($this->getEscaperFilter($type)), $node->getLine())
, $node->getLine()
);
}
else
{
- return new Twig_Node_Expression_Filter($node, array($this->getEscaperFilter()), $node->getLine());
+ return new Twig_Node_Expression_Filter($node, array($this->getEscaperFilter($type)), $node->getLine());
}
}
}
}
- protected function getEscaperFilter()
+ protected function getEscaperFilter($type)
{
- return array('escape', array());
+ return array('escape', array(new Twig_Node_Expression_Constant((string) $type, -1)));
}
}
{
throw new Twig_SyntaxError("Autoescape value must be 'on' or 'off'", $lineno);
}
+ $value = 'on' === $value ? true : false;
+
+ if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE))
+ {
+ if (false === $value)
+ {
+ throw new Twig_SyntaxError(sprintf('Unexpected escaping strategy as you set autoescaping to off.', $lineno), -1);
+ }
+
+ $value = $this->parser->getStream()->next()->getValue();
+ }
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
- return new Twig_Node_AutoEscape('on' === $value ? true : false, $body, $lineno, $this->getTag());
+ return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag());
}
public function decideBlockEnd($token)