From 3c01290c66bd95cb8e881d63426a7c9745e94c40 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 14 Dec 2010 15:19:37 +0100 Subject: [PATCH] fixed usage of operators as method names (like is, in, and not) --- CHANGELOG | 1 + lib/Twig/ExpressionParser.php | 2 +- .../Tests/Fixtures/expressions/method_call.test | 6 ++++++ test/Twig/Tests/integrationTest.php | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 1 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 50efc38..1275fa0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,7 @@ Backward incompatibilities: Changes: + * fixed usage of operators as method names (like is, in, and not) * changed the order of execution for node visitors * fixed default() filter behavior when used with strict_variables set to on * fixed filesystem loader compatibility with PHAR files diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 966674c..5522941 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -235,7 +235,7 @@ class Twig_ExpressionParser $type = Twig_Node_Expression_GetAttr::TYPE_ANY; if ($token->getValue() == '.') { $token = $this->parser->getStream()->next(); - if ($token->getType() == Twig_Token::NAME_TYPE || $token->getType() == Twig_Token::NUMBER_TYPE) { + if ($token->getType() == Twig_Token::NAME_TYPE || $token->getType() == Twig_Token::NUMBER_TYPE || $token->getType() == Twig_Token::OPERATOR_TYPE) { $arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno); if ($this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, '(')) { diff --git a/test/Twig/Tests/Fixtures/expressions/method_call.test b/test/Twig/Tests/Fixtures/expressions/method_call.test index 14674b8..0957d18 100644 --- a/test/Twig/Tests/Fixtures/expressions/method_call.test +++ b/test/Twig/Tests/Fixtures/expressions/method_call.test @@ -8,6 +8,9 @@ Twig supports method calls {{ items.foo.bar('a', 43) }} {{ items.foo.bar(foo) }} {{ items.foo.self.foo() }} +{{ items.foo.is }} +{{ items.foo.in }} +{{ items.foo.not }} --DATA-- return array('foo' => 'bar', 'items' => array('foo' => new Foo(), 'bar' => 'foo')) --EXPECT-- @@ -18,3 +21,6 @@ bar bar_a-43 bar_bar foo +is +in +not diff --git a/test/Twig/Tests/integrationTest.php b/test/Twig/Tests/integrationTest.php index 5f4e20f..7383735 100644 --- a/test/Twig/Tests/integrationTest.php +++ b/test/Twig/Tests/integrationTest.php @@ -97,6 +97,21 @@ class Foo { return $this; } + + public function is() + { + return 'is'; + } + + public function in() + { + return 'in'; + } + + public function not() + { + return 'not'; + } } class TestExtension extends Twig_Extension -- 1.7.2.5