Skip to content

Commit 01906f3

Browse files
committed
[ExpressionLanguage] Compile numbers with var_export in Compiler::repr for thread-safety
1 parent 1ea0ada commit 01906f3

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

Compiler.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,7 @@ public function string(string $value): static
114114
public function repr(mixed $value): static
115115
{
116116
if (\is_int($value) || \is_float($value)) {
117-
if (false !== $locale = setlocale(\LC_NUMERIC, 0)) {
118-
setlocale(\LC_NUMERIC, 'C');
119-
}
120-
121-
$this->raw($value);
122-
123-
if (false !== $locale) {
124-
setlocale(\LC_NUMERIC, $locale);
125-
}
117+
$this->raw(var_export($value, true));
126118
} elseif (null === $value) {
127119
$this->raw('null');
128120
} elseif (\is_bool($value)) {

Tests/Node/ConstantNodeTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,40 @@ public static function getEvaluateData(): array
3131
public static function getCompileData(): array
3232
{
3333
return [
34+
// Booleans
3435
['false', new ConstantNode(false)],
3536
['true', new ConstantNode(true)],
37+
38+
// Null
3639
['null', new ConstantNode(null)],
40+
41+
// Integers
3742
['3', new ConstantNode(3)],
43+
['-10', new ConstantNode(-10)],
44+
['0', new ConstantNode(0)],
45+
46+
// Floats
3847
['3.3', new ConstantNode(3.3)],
48+
['42.0', new ConstantNode(42.0)],
49+
['-1.23', new ConstantNode(-1.23)],
50+
['0.1', new ConstantNode(0.1)],
51+
['1.0', new ConstantNode(1.0)],
52+
['1.0E-6', new ConstantNode(1.0e-6)],
53+
['1.23456789E+20', new ConstantNode(1.23456789e+20)],
54+
['3.3', new ConstantNode(3.2999999999999998)],
55+
['0.30000000000000004', new ConstantNode(0.1 + 0.2)],
56+
['INF', new ConstantNode(\INF)],
57+
['-INF', new ConstantNode(-\INF)],
58+
['NAN', new ConstantNode(\NAN)],
59+
60+
// Strings
3961
['"foo"', new ConstantNode('foo')],
62+
['""', new ConstantNode('')],
63+
['"a\\"b"', new ConstantNode('a"b')],
64+
65+
// Arrays
4066
['[0 => 1, "b" => "a"]', new ConstantNode([1, 'b' => 'a'])],
67+
['[]', new ConstantNode([])],
4168
];
4269
}
4370

0 commit comments

Comments
 (0)