[Form] Fix NumberToLocalizedStringTransformer::reverseTransform with big integers
This commit is contained in:
parent
6b6073f685
commit
03c008cdbf
@ -122,12 +122,16 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
|||||||
$value = str_replace(',', $decSep, $value);
|
$value = str_replace(',', $decSep, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strstr($value, $decSep) && PHP_INT_SIZE === 8) {
|
if (false !== strpos($value, $decSep)) {
|
||||||
$result = $formatter->parse($value, \NumberFormatter::TYPE_INT64, $position);
|
$type = \NumberFormatter::TYPE_DOUBLE;
|
||||||
} else {
|
} else {
|
||||||
$result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
|
$type = PHP_INT_SIZE === 8
|
||||||
|
? \NumberFormatter::TYPE_INT64
|
||||||
|
: \NumberFormatter::TYPE_INT32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = $formatter->parse($value, $type, $position);
|
||||||
|
|
||||||
if (intl_is_failure($formatter->getErrorCode())) {
|
if (intl_is_failure($formatter->getErrorCode())) {
|
||||||
throw new TransformationFailedException($formatter->getErrorMessage());
|
throw new TransformationFailedException($formatter->getErrorMessage());
|
||||||
}
|
}
|
||||||
|
@ -438,6 +438,6 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||||
|
|
||||||
$this->assertEquals(401657096594165125, (int) $transformer->reverseTransform((string) 401657096594165125));
|
$this->assertEquals(PHP_INT_MAX - 1, (int) $transformer->reverseTransform((string) (PHP_INT_MAX - 1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user