From: Fabien Potencier Date: Tue, 15 Oct 2013 16:09:36 +0000 (+0200) Subject: fixed the possibility to have a variable named 'matches' (closes #1227) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=6126457550e62923a2dcf16603512b1bba43144c;p=konrad%2Ftwig.git fixed the possibility to have a variable named 'matches' (closes #1227) --- diff --git a/CHANGELOG b/CHANGELOG index e6b5da1..e3c92c2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.14.1 (2013-XX-XX) + * fixed the possibility to have a variable named 'matches' * added support for PHP 5.5 DateTimeInterface * 1.14.0 (2013-10-03) diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 73be91d..67d3337 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -161,6 +161,13 @@ class Twig_ExpressionParser $node = $this->parseStringExpression(); break; + case Twig_Token::OPERATOR_TYPE: + if ('matches' == $token->getValue()) { + $this->parser->getStream()->next(); + $node = new Twig_Node_Expression_Name('matches', $token->getLine()); + break; + } + default: if ($token->test(Twig_Token::PUNCTUATION_TYPE, '[')) { $node = $this->parseArrayExpression(); diff --git a/test/Twig/Tests/Fixtures/regression/matches_as_variable.test b/test/Twig/Tests/Fixtures/regression/matches_as_variable.test new file mode 100644 index 0000000..00ca200 --- /dev/null +++ b/test/Twig/Tests/Fixtures/regression/matches_as_variable.test @@ -0,0 +1,12 @@ +--TEST-- +Twig allows to use 'matches' for a variable name +--TEMPLATE-- +{% for match in matches %} + {{- match }} +{% endfor %} +--DATA-- +return array('matches' => array(1, 2, 3)) +--EXPECT-- +1 +2 +3