fixed the possibility to have a variable named 'matches' (closes #1227)
authorFabien Potencier <fabien.potencier@gmail.com>
Tue, 15 Oct 2013 16:09:36 +0000 (18:09 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Tue, 15 Oct 2013 16:09:36 +0000 (18:09 +0200)
CHANGELOG
lib/Twig/ExpressionParser.php
test/Twig/Tests/Fixtures/regression/matches_as_variable.test [new file with mode: 0644]

index e6b5da1..e3c92c2 100644 (file)
--- 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)
index 73be91d..67d3337 100644 (file)
@@ -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 (file)
index 0000000..00ca200
--- /dev/null
@@ -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