[Form] Fix handling the empty string in NumberToLocalizedStringTransformer#60676
Conversation
d310abb to
9bf812e
Compare
nicolas-grekas
left a comment
There was a problem hiding this comment.
I can't tell about the change itself, but here is a CS issue :)
...mponent/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php
Outdated
Show resolved
Hide resolved
9bf812e to
eec5f2e
Compare
|
As an aside this is basically doing the other half of #37505 |
xabbuh
left a comment
There was a problem hiding this comment.
Not sure why we didn’t reject numeric strings before as the transformer is expected to work with ints and floats, but as things are this way the change looks valid to me.
| public function transform(mixed $value): string | ||
| { | ||
| if (null === $value) { | ||
| if (null === $value || '' === $value) { |
There was a problem hiding this comment.
Shouldn’t $value PHPdoc be updated to include string?
|
Don't we need the same check in MoneyToLocalizedStringTransformer? |
eec5f2e to
f623d3a
Compare
|
I've pushed another version that includes changes to the docblock and identical changes to MoneyToLocalizedStringTransformer including a test (I didn't run them locally so will push an update if somehow I did it wrong). |
|
Thank you @gnat42. |
The NumberToLocalizedStringTransformer only tests for null, but if the value is an empty string then the test for is_numeric fails. This change makes the reverseTransform and transform methods both test for null or empty strings