From: Fabien Potencier Date: Thu, 2 Dec 2010 13:33:10 +0000 (+0100) Subject: fixed parentheses placement for the ternary operator X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=031bf84b254fb9e8c04b4770f1d4fec077390e99;p=web%2Fkonrad%2Ftwig.git fixed parentheses placement for the ternary operator --- diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index ff2111f..24ff10a 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -56,7 +56,11 @@ class Twig_ExpressionParser $token = $this->parser->getCurrentToken(); } - return $this->parseConditionalExpression($expr); + if (0 === $precedence) { + return $this->parseConditionalExpression($expr); + } + + return $expr; } protected function getPrimary() diff --git a/test/Twig/Tests/Fixtures/expressions/ternary_operator.test b/test/Twig/Tests/Fixtures/expressions/ternary_operator.test index cbf555c..d070824 100644 --- a/test/Twig/Tests/Fixtures/expressions/ternary_operator.test +++ b/test/Twig/Tests/Fixtures/expressions/ternary_operator.test @@ -5,6 +5,7 @@ Twig supports the ternary operator {{ 0 ? 'YES' : 'NO' }} {{ 0 ? 'YES' : (1 ? 'YES1' : 'NO1') }} {{ 0 ? 'YES' : (0 ? 'YES1' : 'NO1') }} +{{ 1 == 1 ? 'foo
':'' }} --DATA-- return array() --EXPECT-- @@ -12,3 +13,4 @@ YES NO YES1 NO1 +foo