From e346c2accfa336b6d7373daeba738ec3284b0755 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 8 Jan 2019 08:53:15 +0100 Subject: [PATCH] fixed float representation in compiled templates --- CHANGELOG | 1 + lib/Twig/Compiler.php | 2 +- test/Twig/Tests/Fixtures/expressions/floats.test | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/Twig/Tests/Fixtures/expressions/floats.test diff --git a/CHANGELOG b/CHANGELOG index 83dc39e04..72e1ba420 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.36.1 (2018-XX-XX) + * fixed float representation in compiled templates * added a second argument to the join filter (last separator configuration) * 1.36.0 (2018-12-16) diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index 803eb8962..b3da4eb5e 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -175,7 +175,7 @@ class Twig_Compiler implements Twig_CompilerInterface setlocale(LC_NUMERIC, 'C'); } - $this->raw($value); + $this->raw(var_export($value, true)); if (false !== $locale) { setlocale(LC_NUMERIC, $locale); diff --git a/test/Twig/Tests/Fixtures/expressions/floats.test b/test/Twig/Tests/Fixtures/expressions/floats.test new file mode 100644 index 000000000..8bf2b1c7e --- /dev/null +++ b/test/Twig/Tests/Fixtures/expressions/floats.test @@ -0,0 +1,14 @@ +--TEST-- +Twig compiles floats properly +--TEMPLATE-- +{% set val2 = 0.0 %} + +{{ val is same as (0.0) ? 'Yes' : 'No' }} +{{ val2 is same as (0.0) ? 'Yes' : 'No' }} +{{ val is same as (val2) ? 'Yes' : 'No' }} +--DATA-- +return array('val' => 0.0) +--EXPECT-- +Yes +Yes +Yes