-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Fix handling the empty string in NumberToLocalizedStringTransformer #60676
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
[Form] Fix handling the empty string in NumberToLocalizedStringTransformer #60676
Conversation
d310abb
to
9bf812e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -50,7 +50,7 @@ public function __construct(?int $scale = null, ?bool $grouping = false, ?int $r | |||
*/ | |||
public function transform(mixed $value): string | |||
{ | |||
if (null === $value) { | |||
if (null === $value || '' === $value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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