Skip to content

Commit

Permalink
bug #18179 [Form] Fix NumberToLocalizedStringTransformer::reverseTran…
Browse files Browse the repository at this point in the history
…sform 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 integers
6b6073f [Form] Fix INT64 cast to float in IntegerType.
  • Loading branch information
nicolas-grekas committed Mar 15, 2016
2 parents afd31da + 03c008c commit 18615fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Expand Up @@ -122,7 +122,15 @@ public function reverseTransform($value)
$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());
Expand Down
Expand Up @@ -433,4 +433,11 @@ public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte()

$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)));
}
}

0 comments on commit 18615fc

Please sign in to comment.