Skip to content
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

Coerce empty string to null #381

Closed
wants to merge 3 commits into from
Closed

Coerce empty string to null #381

wants to merge 3 commits into from

Conversation

shmax
Copy link
Collaborator

@shmax shmax commented Mar 11, 2017

Fix for the null coercion portion of #379

Coerce empty sting to null for type "null".

@erayd @bighappyface @gtuccini

@@ -208,6 +208,9 @@ protected function validateType(&$value, $type)
}

if ('null' === $type) {
if ($coerce) {
$value = $this->toNull($value);
}
return is_null($value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a newline above return is_null($value); to make the style checker happy.

@@ -128,7 +128,7 @@ public function getValidCoerceTests()
"boolean":"true",
"object":{},
"array":[],
"null":null,
"null":"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that you have lots of explicit tests in testValidCoerceCases, in addition to simply requiring the schema to validate, but that null coercion hasn't been added as one of them. Is there a reason for that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. Can you provide an example?

I believe I originally created this file by duplicating BasicTypesTest.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh, I think I get what you mean. One sec...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a post-validate test for null.

I also removed what looked like a duplicated block of explicit tests in the same section of code. Not sure if there was any purpose for it...

@@ -211,6 +211,7 @@ protected function validateType(&$value, $type)
if ($coerce) {
$value = $this->toNull($value);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newline is good, but need to remove the unneeded whitespace on this line.

Copy link
Contributor

@erayd erayd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@erayd
Copy link
Contributor

erayd commented Mar 11, 2017

I think we're good - thanks for doing this PR :-).

@erayd
Copy link
Contributor

erayd commented Mar 14, 2017

@shmax Is this PR still necessary? Seems to me that #384 has made it redundant.

@shmax
Copy link
Collaborator Author

shmax commented Mar 14, 2017

Right you are. Closing...

@shmax shmax closed this Mar 14, 2017
@shmax shmax deleted the coerce-empty-string branch March 14, 2017 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants