From 7d0e5d6a1e071831eb1f4935eea58ba76c7617f2 Mon Sep 17 00:00:00 2001 From: "v.arsentev" Date: Tue, 11 Jan 2022 16:37:06 +0300 Subject: [PATCH 1/2] The deprecated null value for the method round has been changed to zero. --- src/Extension/CoreExtension.php | 4 ++-- tests/Fixtures/filters/round.test | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 2f16d0b8025..e94a900e916 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -581,6 +581,8 @@ function twig_replace_filter($str, $from) */ function twig_round($value, $precision = 0, $method = 'common') { + $value = (float) $value; + if ('common' === $method) { return round($value, $precision); } @@ -589,8 +591,6 @@ function twig_round($value, $precision = 0, $method = 'common') throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.'); } - $value = (float) $value; - return $method($value * 10 ** $precision) / 10 ** $precision; } diff --git a/tests/Fixtures/filters/round.test b/tests/Fixtures/filters/round.test index bb6afcf417d..264b230d19f 100644 --- a/tests/Fixtures/filters/round.test +++ b/tests/Fixtures/filters/round.test @@ -13,6 +13,8 @@ {{ ''|round(-1, 'floor')}} {{ null|round(-1, 'floor')}} +{{ null|round }} +{{ null|round(2, 'ceil') }} --DATA-- return [] --EXPECT-- @@ -28,3 +30,5 @@ return [] 0 0 +0 +0 From b74cf2ae6cdc7e700f4fccda6c9380a19ee3fb02 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Fri, 14 Jan 2022 12:19:38 +0100 Subject: [PATCH 2/2] Rename variables used in map method --- doc/filters/map.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/filters/map.rst b/doc/filters/map.rst index a2ff2a8f8ef..5954da6ccff 100644 --- a/doc/filters/map.rst +++ b/doc/filters/map.rst @@ -27,7 +27,7 @@ The arrow function also receives the key as a second argument: "Alice": "Dupond", } %} - {{ people|map((last, first) => "#{first} #{last}")|join(', ') }} + {{ people|map((value, key) => "#{value} #{key}")|join(', ') }} {# outputs Bob Smith, Alice Dupond #} Note that the arrow function has access to the current context.