From 6126457550e62923a2dcf16603512b1bba43144c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 15 Oct 2013 18:09:36 +0200 Subject: [PATCH] fixed the possibility to have a variable named 'matches' (closes #1227) --- CHANGELOG | 1 + lib/Twig/ExpressionParser.php | 7 +++++++ .../Fixtures/regression/matches_as_variable.test | 12 ++++++++++++ 3 files changed, 20 insertions(+), 0 deletions(-) create mode 100644 test/Twig/Tests/Fixtures/regression/matches_as_variable.test 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 -- 1.7.2.5