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
-------
4225f36b86
parse numbers terminated with decimal separator
This commit is contained in:
commit
40b547e122
@ -516,7 +516,7 @@ class NumberFormatter
|
|||||||
$groupSep = $this->getAttribute(self::GROUPING_USED) ? ',' : '';
|
$groupSep = $this->getAttribute(self::GROUPING_USED) ? ',' : '';
|
||||||
|
|
||||||
// Any string before the numeric value causes error in the parsing
|
// 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];
|
$value = $matches[0];
|
||||||
$position = \strlen($value);
|
$position = \strlen($value);
|
||||||
if ($error = $groupSep && isset($matches[1]) && !preg_match('/^\d{1,3}+(?:(?:,\d{3})++|\d*+)$/', $matches[1])) {
|
if ($error = $groupSep && isset($matches[1]) && !preg_match('/^\d{1,3}+(?:(?:,\d{3})++|\d*+)$/', $matches[1])) {
|
||||||
|
@ -654,6 +654,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||||||
array('-123,4567', false, '->parse() does not parse when invalid grouping used.', 9),
|
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', false, '->parse() does not parse when invalid grouping used.', 4),
|
||||||
array('-123,,456', -123.0, '->parse() parses when grouping is disabled.', 4, false),
|
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),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user