Skip to content

[Form] Fix NumberToLocalizedStringTransformer::reverseTransform with big integers #18179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor comment: should this ternary condition be a one-liner?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wouldn't enhance readability imho

? \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
Original file line number Diff line number Diff line change
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)));
}
}
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