Skip to content

Make sure '0' edge case is properly handled by is_json()#4634

Closed
kirtangajjar wants to merge 1 commit intowp-cli:masterfrom
kirtangajjar:patch-1
Closed

Make sure '0' edge case is properly handled by is_json()#4634
kirtangajjar wants to merge 1 commit intowp-cli:masterfrom
kirtangajjar:patch-1

Conversation

@kirtangajjar
Copy link
Contributor

Fixed #4629 - Broken 0 edge case in WP_CLI\Utils\is_json()

Fixed wp-cli#4629 - Broken `0` edge case in `WP_CLI\Utils\is_json()`
Copy link
Contributor

@gitlost gitlost left a comment

Choose a reason for hiding this comment

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

Thanks v much @kirtangajjar ! Could you also add these test cases

array( '0', true, false ),
array( '0', false, true ),
array( '', true, false ),
array( '', false, false ),

to dataIsJson() in "tests/test-utils.php" please?

*/
function is_json( $argument, $ignore_scalars = true ) {
if ( empty( $argument ) || ! is_string( $argument ) ) {
if ( ! is_string( $argument ) || 0 === strlen( $argument ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry just to be "modern" could you change this to:

if ( ! is_string( $argument ) || '' === $argument ) {

please? (My fault).

@gitlost gitlost added this to the 1.5.0 milestone Jan 24, 2018
@schlessera schlessera changed the title Fixed Broken #4629 Make sure '0' edge case is properly handled by is_json() Jan 24, 2018
@kirtangajjar
Copy link
Contributor Author

kirtangajjar commented Jan 24, 2018

Sorry looks like I accidentially created new PR #4635. I published commit to my patch-1 branch, but somehow it didn't show here :/

@gitlost
Copy link
Contributor

gitlost commented Jan 24, 2018

Ok it's probably easiest if I close this and use the other one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants