Skip to content

Commit 3527360

Browse files
authored
Merge pull request #7157 from kenjis/fix-parser-local_currency
fix: [Parser] local_currency causes "Passing null to parameter"
2 parents 74056b6 + 49e7c04 commit 3527360

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

system/View/Filters.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ public static function local_currency($value, string $currency, ?string $locale
171171
{
172172
helper('number');
173173

174+
$fraction ??= 0;
175+
174176
$options = [
175177
'type' => NumberFormatter::CURRENCY,
176178
'currency' => $currency,

tests/system/View/ParserFilterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,20 @@ public function testLocalCurrency()
396396
$this->assertSame("1.234.567,89\u{a0}", $parser->renderString($template));
397397
}
398398

399+
public function testLocalCurrencyWithoutFraction()
400+
{
401+
$parser = new Parser($this->config, $this->viewsDir, $this->loader);
402+
403+
$data = [
404+
'mynum' => 1_234_567.8912346,
405+
];
406+
407+
$template = '{ mynum|local_currency(EUR,de_DE) }';
408+
409+
$parser->setData($data);
410+
$this->assertSame("1.234.568\u{a0}", $parser->renderString($template));
411+
}
412+
399413
public function testParsePairWithAbs()
400414
{
401415
$parser = new Parser($this->config, $this->viewsDir, $this->loader);

user_guide_src/source/outgoing/view_parser.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,9 @@ limit_chars limit Limits the number of characters to $limit.
389389

390390
limit_words limit Limits the number of words to $limit. { v|limit_words(20) }
391391

392-
local_currency currency, locale Displays a localized version of a currency. "currency" { v|local_currency(EUR,en_US) }
393-
valueis any 3-letter ISO 4217 currency code.
392+
local_currency currency, Displays a localized version of a currency. "currency" { v|local_currency(EUR,en_US) }
393+
locale, valueis any 3-letter ISO 4217 currency code.
394+
fraction
394395

395396
local_number type, precision, Displays a localized version of a number. "type" can be { v|local_number(decimal,2,en_US) }
396397
locale one of: decimal, currency, percent, scientific, spellout,

0 commit comments

Comments
 (0)