Skip to content

Commit

Permalink
bug #4498 Fix the Elvis operator when there is some space between ? a…
Browse files Browse the repository at this point in the history
…nd : (fabpot)

This PR was merged into the 3.x branch.

Discussion
----------

Fix the Elvis operator when there is some space between ? and :

Commits
-------

1af334b Fix the Elvis operator when there is some space between ? and :
  • Loading branch information
fabpot committed Dec 11, 2024
2 parents 31f61bd + 1af334b commit 47f527e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 3.17.1 (2024-XX-XX)

* n/a
* Fix the Elvis operator when used as '? :' instead of '?:'

# 3.17.0 (2024-12-10)

Expand Down
1 change: 1 addition & 0 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public function getOperators(): array
'+' => ['precedence' => 500, 'class' => PosUnary::class],
],
[
'? :' => ['precedence' => 5, 'class' => ElvisBinary::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT],
'?:' => ['precedence' => 5, 'class' => ElvisBinary::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT],
'??' => ['precedence' => 300, 'precedence_change' => new OperatorPrecedenceChange('twig/twig', '3.15', 5), 'class' => NullCoalesceBinary::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT],
'or' => ['precedence' => 10, 'class' => OrBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/expressions/ternary_operator_nothen.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ Twig supports the ternary operator
--TEMPLATE--
{{ 'YES' ?: 'NO' }}
{{ 0 ?: 'NO' }}
{{ 'YES' ? : 'NO' }}
{{ 0 ? : 'NO' }}
{{ 'YES' ? : 'NO' }}
{{ 0 ? : 'NO' }}
--DATA--
return []
--EXPECT--
YES
NO
YES
NO
YES
NO

0 comments on commit 47f527e

Please sign in to comment.