-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Fixed #11675 ValueToDuplicatesTransformer accept "0" value #11676
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
Conversation
Nek-
commented
Aug 15, 2014
Q | A |
---|---|
Bug fix? | [yes] |
New feature? | [no] |
BC breaks? | [no] |
Deprecations? | [no] |
Tests pass? | [yes] |
Fixed tickets | #11675 |
License | MIT |
@@ -64,7 +64,7 @@ public function reverseTransform($array) | |||
$emptyKeys = array(); | |||
|
|||
foreach ($this->keys as $key) { | |||
if (!empty($array[$key])) { | |||
if (isset($array[$key]) && $array[$key] !== null && $array[$key] !== '' && $array !== false) { |
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.
what about empty arrays as values ?
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.
Nice catch. I'm gonna add this test.
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.
isset($array[$key]) && $array[$key] !== null
is basically the same thing (isset returns false if the key $key
is null
)
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.
@Taluu not exactly the same. isset($array[$key])
covers more cases that $array[$key] !== null
. It covers null
values, but not missing values. So $array[$key] !== null
is indeed not necessary here, but both conditions are not the same thing.
@Nek- please also switch the order of operands for each condition. We are using Yoda conditions in Symfony
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.
done
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.
@stof Yup, that's what I meant (the null comparision is done by the isset
verification). My bad if there was a misunderstanding. :)
note to maintainers: the fix should be merged to 2.3 |
Fixed wrong return null syntax Added transformation to null on empty arrays Removed useless statement in condition and switched to yoda condition
👍 |
Good catch, thanks Maxime. |
…" value (Nek-) This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11676). Discussion ---------- [Form] Fixed #11675 ValueToDuplicatesTransformer accept "0" value | Q | A | ------------- | --- | Bug fix? | [yes] | New feature? | [no] | BC breaks? | [no] | Deprecations? | [no] | Tests pass? | [yes] | Fixed tickets | #11675 | License | MIT Commits ------- 31d48ab Fixed #11675 ValueToDuplicatesTransformer accept "0" value
👍 |