mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 19:36:43 +00:00
bug #3344 Fix the compilation of Twig comparison operators (stof)
This PR was merged into the 3.x branch.
Discussion
----------
Fix the compilation of Twig comparison operators
The new compilation implemented in Twig 3 for PHP 7 (to match the comparison semantic of PHP 8) was missing the surrounding braces (which are part of the AsbtractBinary compilation). This caused issues when the full expression would involve other operators (like the not operator), as things would then rely on having the correct precedence in PHP (which would not be the case).
Closes #3318
Commits
-------
bf24f136 Fix the compilation of Twig comparison operators
This commit is contained in:
@@ -24,11 +24,11 @@ class EqualBinary extends AbstractBinary
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('0 === twig_compare(')
|
||||
->raw('(0 === twig_compare(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('right'))
|
||||
->raw(')')
|
||||
->raw('))')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ class GreaterBinary extends AbstractBinary
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('1 === twig_compare(')
|
||||
->raw('(1 === twig_compare(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('right'))
|
||||
->raw(')')
|
||||
->raw('))')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ class GreaterEqualBinary extends AbstractBinary
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('0 <= twig_compare(')
|
||||
->raw('(0 <= twig_compare(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('right'))
|
||||
->raw(')')
|
||||
->raw('))')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ class LessBinary extends AbstractBinary
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('-1 === twig_compare(')
|
||||
->raw('(-1 === twig_compare(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('right'))
|
||||
->raw(')')
|
||||
->raw('))')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ class LessEqualBinary extends AbstractBinary
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('0 >= twig_compare(')
|
||||
->raw('(0 >= twig_compare(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('right'))
|
||||
->raw(')')
|
||||
->raw('))')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ class NotEqualBinary extends AbstractBinary
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('0 !== twig_compare(')
|
||||
->raw('(0 !== twig_compare(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('right'))
|
||||
->raw(')')
|
||||
->raw('))')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
Twig comparison operators precendence
|
||||
--TEMPLATE--
|
||||
{{ not(1 > 2) }}/{{ not(1 > 1) }}/{{ not(1 >= 2) }}/{{ not(1 >= 1) }}
|
||||
{{ not(1 < 2) }}/{{ not(1 < 1) }}/{{ not(1 <= 2) }}/{{ not(1 <= 1) }}
|
||||
{{ not(1 == 1) }}/{{ not(1 == 2) }}
|
||||
{{ not(1 != 1) }}/{{ not(1 != 2) }}
|
||||
--DATA--
|
||||
return []
|
||||
--EXPECT--
|
||||
1/1/1/
|
||||
/1//
|
||||
/1
|
||||
1/
|
||||
Reference in New Issue
Block a user