Skip to content

Coerce empty string to null - #381

Closed
shmax wants to merge 3 commits into
jsonrainbow:masterfrom
shmax:coerce-empty-string
Closed

Coerce empty string to null#381
shmax wants to merge 3 commits into
jsonrainbow:masterfrom
shmax:coerce-empty-string

Conversation

@shmax

@shmax shmax commented Mar 11, 2017

Copy link
Copy Markdown
Collaborator

Fix for the null coercion portion of #379

Coerce empty sting to null for type "null".

@erayd @bighappyface @gtuccini

if ($coerce) {
$value = $this->toNull($value);
}
return is_null($value);

Copy link
Copy Markdown
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.

"object":{},
"array":[],
"null":null,
"null":"",

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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...

if ($coerce) {
$value = $this->toNull($value);
}

Copy link
Copy Markdown
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.

@erayd erayd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@erayd

erayd commented Mar 11, 2017

Copy link
Copy Markdown
Contributor

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

@erayd

erayd commented Mar 14, 2017

Copy link
Copy Markdown
Contributor

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

@shmax

shmax commented Mar 14, 2017

Copy link
Copy Markdown
Collaborator Author

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.

3 participants