mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-29 23:26:44 +00:00
Fix compiled float literals depending on the serialize_precision ini setting
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# 3.31.0 (2026-XX-XX)
|
||||
|
||||
* Fix compiled float literals depending on the `serialize_precision` ini setting
|
||||
* Fix the `loop` variable being undefined when used in the sequence of a nested `for` tag
|
||||
* Reject a deprecated `Template` instance created by another environment in `Environment::resolveTemplate()`
|
||||
* Fix a compilation error inside an `autoescape` tag leaking its escaping strategy into the next compiled template
|
||||
|
||||
@@ -166,8 +166,15 @@ class Compiler
|
||||
setlocale(\LC_NUMERIC, 'C');
|
||||
}
|
||||
|
||||
// var_export() follows serialize_precision, -1 gives the shortest representation that reads back as the same float
|
||||
$precision = \is_float($value) ? ini_set('serialize_precision', '-1') : false;
|
||||
|
||||
$this->raw(var_export($value, true));
|
||||
|
||||
if (false !== $precision) {
|
||||
ini_set('serialize_precision', $precision);
|
||||
}
|
||||
|
||||
if (false !== $locale) {
|
||||
setlocale(\LC_NUMERIC, $locale);
|
||||
}
|
||||
|
||||
@@ -64,4 +64,17 @@ class CompilerTest extends TestCase
|
||||
|
||||
setlocale(\LC_NUMERIC, $locale);
|
||||
}
|
||||
|
||||
public function testReprFloatDoesNotDependOnSerializePrecision(): void
|
||||
{
|
||||
$compiler = new Compiler(new Environment(new ArrayLoader()));
|
||||
$precision = ini_set('serialize_precision', '17');
|
||||
|
||||
try {
|
||||
$this->assertSame('0.1', $compiler->repr(0.1)->getSource());
|
||||
$this->assertSame('17', \ini_get('serialize_precision'));
|
||||
} finally {
|
||||
ini_set('serialize_precision', $precision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user