fix parsing of postfix expressions
authorArnaud Le Blanc <arnaud.lb@gmail.com>
Sun, 28 Nov 2010 20:01:23 +0000 (21:01 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Mon, 29 Nov 2010 07:05:26 +0000 (08:05 +0100)
lib/Twig/ExpressionParser.php
test/Twig/Tests/Fixtures/expressions/expressions.test [new file with mode: 0644]

index a014c94..ff2111f 100644 (file)
@@ -69,13 +69,13 @@ class Twig_ExpressionParser
             $expr = $this->parseExpression($operator['precedence']);
             $class = $operator['class'];
 
-            return new $class($expr, $token->getLine());
+            return $this->parsePostfixExpression(new $class($expr, $token->getLine()));
         } elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
             $this->parser->getStream()->next();
             $expr = $this->parseExpression();
             $this->parser->getStream()->expect(Twig_Token::PUNCTUATION_TYPE, ')');
 
-            return $expr;
+            return $this->parsePostfixExpression($expr);
         }
 
         return $this->parsePrimaryExpression();
diff --git a/test/Twig/Tests/Fixtures/expressions/expressions.test b/test/Twig/Tests/Fixtures/expressions/expressions.test
new file mode 100644 (file)
index 0000000..db047c0
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Twig parses postfix expressions
+--TEMPLATE--
+
+{% macro foo() %}foo{% endmacro %}
+
+{{ 'a' }}
+{{ 'a'|upper }}
+{{ ('a')|upper }}
+{{ -1|upper }}
+{{ _self.foo() }}
+{{ (_self).foo() }}
+--DATA--
+return array();
+--EXPECT--
+a
+A
+A
+-1
+foo
+foo