mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 18:36:53 +00:00
Fix twig_compare float-string trailing whitespace + refactor
This commit is contained in:
committed by
Fabien Potencier
parent
d291382a24
commit
d6822aebcf
@@ -971,16 +971,18 @@ function twig_compare($a, $b)
|
||||
if (is_nan($a)) {
|
||||
return 1;
|
||||
}
|
||||
$b = trim($b);
|
||||
if (!is_numeric($b)) {
|
||||
return (string) $a <=> $b;
|
||||
}
|
||||
|
||||
return (float) $a <=> $b;
|
||||
return $a <=> (float) $b;
|
||||
}
|
||||
if (\is_float($b) && \is_string($a)) {
|
||||
if (\is_string($a) && \is_float($b)) {
|
||||
if (is_nan($b)) {
|
||||
return 1;
|
||||
}
|
||||
$a = trim($a);
|
||||
if (!is_numeric($a)) {
|
||||
return $a <=> (string) $b;
|
||||
}
|
||||
|
||||
@@ -306,6 +306,12 @@ class CoreTest extends TestCase
|
||||
[-1, 42, 'abc42'],
|
||||
[-1, 0, 'abc42'],
|
||||
|
||||
[0, 42.0, ' 42.0'],
|
||||
[0, 42.0, '42.0 '],
|
||||
[-1, 42.0, '42.0abc'],
|
||||
[-1, 42.0, 'abc42.0'],
|
||||
[-1, 0.0, 'abc42.0'],
|
||||
|
||||
[0, INF, 'INF'],
|
||||
[0, -INF, '-INF'],
|
||||
[0, INF, '1e1000'],
|
||||
|
||||
Reference in New Issue
Block a user