From 4225f36b8646e2b503b2e9c00c17c0bdb08f413f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 21 Sep 2018 15:59:15 +0200 Subject: [PATCH] parse numbers terminated with decimal separator --- src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php | 2 +- .../Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php index e63e3c4349..ea1eb1b7a3 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php @@ -516,7 +516,7 @@ class NumberFormatter $groupSep = $this->getAttribute(self::GROUPING_USED) ? ',' : ''; // Any string before the numeric value causes error in the parsing - if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d++)?)/", $value, $matches)) { + if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d*+)?)/", $value, $matches)) { $value = $matches[0]; $position = \strlen($value); if ($error = $groupSep && isset($matches[1]) && !preg_match('/^\d{1,3}+(?:(?:,\d{3})++|\d*+)$/', $matches[1])) { diff --git a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php index 0e10f7d374..ece5ad5625 100644 --- a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php @@ -654,6 +654,7 @@ abstract class AbstractNumberFormatterTest extends TestCase array('-123,4567', false, '->parse() does not parse when invalid grouping used.', 9), array('-123,,456', false, '->parse() does not parse when invalid grouping used.', 4), array('-123,,456', -123.0, '->parse() parses when grouping is disabled.', 4, false), + array('239.', 239.0, '->parse() parses when string ends with decimal separator.', 4, false), ); }