Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #3186 Fix twig compare (dpinheiro)
This PR was squashed before being merged into the 3.x branch (closes #3186). Discussion ---------- Fix twig compare On twig 2.x the comparison between two variables was being done using the php operators (<, >, <=..), although on 3.x the function `twig_compare` was introduced and it had some issues As an example `'200' > 399` was returning `false` on twig 2.x, but on 3.x it was returning `true`. Digging into the code I found out the comparison binaries (`GreaterBinary`, `LessBinary`, etc) were doing the wrong comparison, and the function `twig_compare` was also returning an wrong value if both variables had the same type Now it's following the convention `-1` if first var is less, 0 if they are equal, or 1 if first var is greater This is my first PR, so please comment if anything is wrong Commits ------- 0d81c6e Fix twig compare
- Loading branch information
Showing
6 changed files
with
12 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -989,7 +989,7 @@ function twig_compare($a, $b) | |
} | ||
|
||
// fallback to <=> | ||
return $b <=> $a; | ||
return $a <=> $b; | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters