Skip to content

Commit 18615fc

Browse files
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 integers 6b6073f [Form] Fix INT64 cast to float in IntegerType.
2 parents afd31da + 03c008c commit 18615fc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

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

125-
$result = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE, $position);
125+
if (false !== strpos($value, $decSep)) {
126+
$type = \NumberFormatter::TYPE_DOUBLE;
127+
} else {
128+
$type = PHP_INT_SIZE === 8
129+
? \NumberFormatter::TYPE_INT64
130+
: \NumberFormatter::TYPE_INT32;
131+
}
132+
133+
$result = $formatter->parse($value, $type, $position);
126134

127135
if (intl_is_failure($formatter->getErrorCode())) {
128136
throw new TransformationFailedException($formatter->getErrorMessage());

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,11 @@ public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte()
433433

434434
$transformer->reverseTransform("12\xc2\xa0345,678foo");
435435
}
436+
437+
public function testReverseTransformBigint()
438+
{
439+
$transformer = new NumberToLocalizedStringTransformer(null, true);
440+
441+
$this->assertEquals(PHP_INT_MAX - 1, (int) $transformer->reverseTransform((string) (PHP_INT_MAX - 1)));
442+
}
436443
}

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