bug #18179 [Form] Fix NumberToLocalizedStringTransformer::reverseTransform with big integers (ovrflo, nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- [Form] Fix NumberToLocalizedStringTransformer::reverseTransform with big integers | Q | A | ------------- | --- | Branch | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18077, #18067 | License | MIT | Doc PR | - Commits -------03c008c
[Form] Fix NumberToLocalizedStringTransformer::reverseTransform with big integers6b6073f
[Form] Fix INT64 cast to float in IntegerType.
This commit is contained in:
commit
18615fccf0
|
@ -122,7 +122,15 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
|||
$value = str_replace(',', $decSep, $value);
|
||||
}
|
||||
|
||||
$result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
|
||||
if (false !== strpos($value, $decSep)) {
|
||||
$type = \NumberFormatter::TYPE_DOUBLE;
|
||||
} else {
|
||||
$type = PHP_INT_SIZE === 8
|
||||
? \NumberFormatter::TYPE_INT64
|
||||
: \NumberFormatter::TYPE_INT32;
|
||||
}
|
||||
|
||||
$result = $formatter->parse($value, $type, $position);
|
||||
|
||||
if (intl_is_failure($formatter->getErrorCode())) {
|
||||
throw new TransformationFailedException($formatter->getErrorMessage());
|
||||
|
|
|
@ -433,4 +433,11 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$transformer->reverseTransform("12\xc2\xa0345,678foo");
|
||||
}
|
||||
|
||||
public function testReverseTransformBigint()
|
||||
{
|
||||
$transformer = new NumberToLocalizedStringTransformer(null, true);
|
||||
|
||||
$this->assertEquals(PHP_INT_MAX - 1, (int) $transformer->reverseTransform((string) (PHP_INT_MAX - 1)));
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue