8000 don't reject floats in StringToFloatTransformer · symfony/symfony@292de1c · GitHub
[go: up one dir, main page]

Skip to content

Commit 292de1c

Browse files
committed
don't reject floats in StringToFloatTransformer
1 parent 030396a commit 292de1c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function transform($value)
3434
return null;
3535
}
3636

37-
if (!\is_string($value) || !is_numeric($value)) {
37+
if ((!\is_string($value) || !is_numeric($value)) && !\is_float($value)) {
3838
throw new TransformationFailedException('Expected a numeric string.');
3939
}
4040

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function provideTransformations(): array
3636
['1.', 1.],
3737
['1.0', 1.],
3838
['1.23', 1.23],
39+
[1.23, 1.23],
3940
];
4041
}
4142

@@ -55,13 +56,13 @@ public function testTransform($from, $to): void
5556
public function testFailIfTransformingANonString(): void
5657
{
5758
$transformer = new StringToFloatTransformer();
58-
$transformer->transform(1.0);
59+
$transformer->transform([1.0]);
5960
}
6061

6162
/**
6263
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
6364
*/
64-
public function testFailIfTransformingANonNumericString(): void
65+
public function testFailIfTransformingNonNumericValues(): void
6566
{
6667
$transformer = new StringToFloatTransformer();
6768
$transformer->transform('foobar');

0 commit comments

Comments
 (0)
0