merged branch bschussek/issue3161 (PR #3204)
Commits -------0533c1b
[Form] Fixed: IntegerToLocalizedStringTransformer does not accept "NaN" as valid number anymore8c63d6d
[Form] Fixed: NumberToLocalizedStringTransformer does not accept "NaN" as valid number anymoreaaa9de6
Added test case for checking that 'NaN' string converts into TransformationFailedException in NumberToLocalizedStringTransformer Discussion ---------- [Form] Disallowed "NaN" as input in number fields Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: #3161, #3196 Todo: nothing ![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue3161)
This commit is contained in:
commit
ff23e725f4
@ -35,6 +35,10 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
|
||||
return null;
|
||||
}
|
||||
|
||||
if ('NaN' === $value) {
|
||||
throw new TransformationFailedException('"NaN" is not a valid integer');
|
||||
}
|
||||
|
||||
$formatter = $this->getNumberFormatter();
|
||||
$value = $formatter->parse(
|
||||
$value,
|
||||
|
@ -103,6 +103,10 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
if ('NaN' === $value) {
|
||||
throw new TransformationFailedException('"NaN" is not a valid number');
|
||||
}
|
||||
|
||||
$formatter = $this->getNumberFormatter();
|
||||
$value = $formatter->parse($value);
|
||||
|
||||
|
@ -70,4 +70,24 @@ class IntegerToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
|
||||
$transformer->reverseTransform('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformDisallowsNaN()
|
||||
{
|
||||
$transformer = new IntegerToLocalizedStringTransformer();
|
||||
|
||||
$transformer->reverseTransform('NaN');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformDisallowsNaN2()
|
||||
{
|
||||
$transformer = new IntegerToLocalizedStringTransformer();
|
||||
|
||||
$transformer->reverseTransform('nan');
|
||||
}
|
||||
}
|
||||
|
@ -123,4 +123,25 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
|
||||
$transformer->reverseTransform('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
* @link https://github.com/symfony/symfony/issues/3161
|
||||
*/
|
||||
public function testReverseTransformDisallowsNaN()
|
||||
{
|
||||
$transformer = new NumberToLocalizedStringTransformer();
|
||||
|
||||
$transformer->reverseTransform('NaN');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformDisallowsNaN2()
|
||||
{
|
||||
$transformer = new NumberToLocalizedStringTransformer();
|
||||
|
||||
$transformer->reverseTransform('nan');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user