Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b32dfda

Browse files
authored
Merge pull request wp-cli#4635 from kirtangajjar/upstream/patch-1
Make sure '0' edge case is properly handled by is_json()
2 parents 12aa162 + c8c04ab commit b32dfda

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

php/utils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ function esc_sql_ident( $idents ) {
14161416
* @return bool Whether the provided string is a valid JSON representation.
14171417
*/
14181418
function is_json( $argument, $ignore_scalars = true ) {
1419-
if ( empty( $argument ) || ! is_string( $argument ) ) {
1419+
if ( ! is_string( $argument ) || '' === $argument ) {
14201420
return false;
14211421
}
14221422

tests/test-utils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,10 @@ public function dataIsJson() {
711711
array( '{"key1":"value1","key2":"value2"}', false, true ),
712712
array( '["value1","value2"]', true, true ),
713713
array( '["value1","value2"]', false, true ),
714+
array( '0', true, false ),
715+
array( '0', false, true ),
716+
array( '', true, false ),
717+
array( '', false, false ),
714718
);
715719
}
716720

0 commit comments

Comments
 (0)