Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40b547e

Browse files
bug #28540 [Intl] parse numbers terminated with decimal separator (xabbuh)
This PR was merged into the 2.8 branch. Discussion ---------- [Intl] parse numbers terminated with decimal separator | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28500 | License | MIT | Doc PR | Commits ------- 4225f36 parse numbers terminated with decimal separator
2 parents 2c8c6f7 + 4225f36 commit 40b547e

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public function parse($value, $type = self::TYPE_DOUBLE, &$position = 0)
516516
$groupSep = $this->getAttribute(self::GROUPING_USED) ? ',' : '';
517517

518518
// Any string before the numeric value causes error in the parsing
519-
if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d++)?)/", $value, $matches)) {
519+
if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d*+)?)/", $value, $matches)) {
520520
$value = $matches[0];
521521
$position = \strlen($value);
522522
if ($error = $groupSep && isset($matches[1]) && !preg_match('/^\d{1,3}+(?:(?:,\d{3})++|\d*+)$/', $matches[1])) {

src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ public function parseProvider()
654654
array('-123,4567', false, '->parse() does not parse when invalid grouping used.', 9),
655655
array('-123,,456', false, '->parse() does not parse when invalid grouping used.', 4),
656656
array('-123,,456', -123.0, '->parse() parses when grouping is disabled.', 4, false),
657+
array('239.', 239.0, '->parse() parses when string ends with decimal separator.', 4, false),
657658
);
658659
}
659660

0 commit comments

Comments
 (0)