mirror of
https://github.com/php/php-src.git
synced 2025-08-18 06:58:55 +02:00
There is no error code set for json_last_error if an invalid utf8
sequence is encountered. This fixes that. Might be worthwhile to merge to 5.3 despite the new constant.
This commit is contained in:
parent
d1d69cc796
commit
f0fb480b13
2 changed files with 4 additions and 0 deletions
|
@ -24,6 +24,7 @@ enum error_codes {
|
|||
PHP_JSON_ERROR_STATE_MISMATCH,
|
||||
PHP_JSON_ERROR_CTRL_CHAR,
|
||||
PHP_JSON_ERROR_SYNTAX,
|
||||
PHP_JSON_ERROR_UTF8,
|
||||
};
|
||||
|
||||
extern JSON_parser new_JSON_parser(int depth);
|
||||
|
|
|
@ -93,6 +93,7 @@ static PHP_MINIT_FUNCTION(json)
|
|||
REGISTER_LONG_CONSTANT("JSON_ERROR_STATE_MISMATCH", PHP_JSON_ERROR_STATE_MISMATCH, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("JSON_ERROR_CTRL_CHAR", PHP_JSON_ERROR_CTRL_CHAR, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("JSON_ERROR_SYNTAX", PHP_JSON_ERROR_SYNTAX, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("JSON_ERROR_UTF8", PHP_JSON_ERROR_UTF8, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -311,6 +312,7 @@ static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar type,
|
|||
efree(utf16);
|
||||
}
|
||||
if (len < 0) {
|
||||
JSON_G(error_code) = PHP_JSON_ERROR_UTF8;
|
||||
if (!PG(display_errors)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid UTF-8 sequence in argument");
|
||||
}
|
||||
|
@ -538,6 +540,7 @@ static PHP_FUNCTION(json_decode)
|
|||
if (utf16) {
|
||||
efree(utf16);
|
||||
}
|
||||
JSON_G(error_code) = PHP_JSON_ERROR_UTF8;
|
||||
RETURN_NULL();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue