MFH Fix bug #45989 - json_decode() doesn't return NULL on certain invalid strings

This commit is contained in:
Scott MacVicar 2008-12-12 23:19:47 +00:00
parent dddbfccb9f
commit ed5f04710b
3 changed files with 10 additions and 17 deletions

View File

@ -523,13 +523,7 @@ static PHP_FUNCTION(json_decode)
RETURN_DOUBLE(d); RETURN_DOUBLE(d);
} }
} }
if (str_len > 1 && *str == '"' && str[str_len-1] == '"') { RETURN_NULL();
RETURN_STRINGL(str+1, str_len-2, 1);
} else if (*str == '{' || *str == '[') { /* invalid JSON string */
RETURN_NULL();
} else {
RETURN_STRINGL(str, str_len, 1);
}
} }
} }
/* }}} */ /* }}} */

View File

@ -31,12 +31,12 @@ NULL
NULL NULL
NULL NULL
NULL NULL
string(1) "." NULL
string(1) "." NULL
string(3) "<?>" NULL
string(1) ";" NULL
string(12) "руссиш" NULL
string(4) "blah" NULL
NULL NULL
object(stdClass)#1 (1) { object(stdClass)#1 (1) {
["test"]=> ["test"]=>

View File

@ -16,10 +16,9 @@ var_dump(
?> ?>
--EXPECT-- --EXPECT--
string(0) "" string(0) ""
string(5) "".."." NULL
string(1) """ NULL
string(2) """" NULL
string(4) ""\""" string(4) ""\"""
string(1) """ string(1) """
string(2) """" string(2) """"