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:
Nicolas Grekas 2018-09-22 09:42:26 +02:00
commit 40b547e122
2 changed files with 2 additions and 1 deletions

View File

@ -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])) {

View File

@ -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),
);
}