Skip to content

Commit 03c008c

Browse files
[Form] Fix NumberToLocalizedStringTransformer::reverseTransform with big integers
1 parent 6b6073f commit 03c008c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,16 @@ public function reverseTransform($value)
122122
$value = str_replace(',', $decSep, $value);
123123
}
124124

125-
if (!strstr($value, $decSep) && PHP_INT_SIZE === 8) {
126-
$result = $formatter->parse($value, \NumberFormatter::TYPE_INT64, $position);
125+
if (false !== strpos($value, $decSep)) {
126+
$type = \NumberFormatter::TYPE_DOUBLE;
127127
} else {
128-
$result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
128+
$type = PHP_INT_SIZE === 8
129+
? \NumberFormatter::TYPE_INT64
130+
: \NumberFormatter::TYPE_INT32;
129131
}
130132

133+
$result = $formatter->parse($value, $type, $position);
134+
131135
if (intl_is_failure($formatter->getErrorCode())) {
132136
throw new TransformationFailedException($formatter->getErrorMessage());
133137
}

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,6 @@ public function testReverseTransformBigint()
438438
{
439439
$transformer = new NumberToLocalizedStringTransformer(null, true);
440440

441-
$this->assertEquals(401657096594165125, (int) $transformer->reverseTransform((string) 401657096594165125));
441+
$this->assertEquals(PHP_INT_MAX - 1, (int) $transformer->reverseTransform((string) (PHP_INT_MAX - 1)));
442442
}
443443
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy