Skip to content

[Form] Handle all case variants of "nan" when parsing a number #29343

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
Nov 29, 2018
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 @@ -146,7 +146,7 @@ public function reverseTransform($value)
return;
}

if ('NaN' === $value) {
if (\in_array($value, array('NaN', 'NAN', 'nan'), true)) {
throw new TransformationFailedException('"NaN" is not a valid number');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,24 +514,24 @@ public function testReverseTransformExpectsValidNumber()

/**
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
* @dataProvider nanRepresentationProvider
*
* @see https://github.com/symfony/symfony/issues/3161
*/
public function testReverseTransformDisallowsNaN()
public function testReverseTransformDisallowsNaN($nan)
{
$transformer = new NumberToLocalizedStringTransformer();

$transformer->reverseTransform('NaN');
$transformer->reverseTransform($nan);
}

/**
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
*/
public function testReverseTransformDisallowsNaN2()
public function nanRepresentationProvider()
{
$transformer = new NumberToLocalizedStringTransformer();

$transformer->reverseTransform('nan');
return array(
array('nan'),
array('NaN'), // see https://github.com/symfony/symfony/issues/3161
array('NAN'),
);
}

/**
Expand Down