From: Scott MacVicar Date: Mon, 27 Jul 2009 03:43:38 +0000 (+0000) Subject: MFH: Add error constant when json_encode detects an invalid UTF-8 sequence. X-Git-Tag: php-5.3.1RC1~253 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87dbefa03b02c7ec6e79654a04fe3b8b285b0be7;p=php MFH: Add error constant when json_encode detects an invalid UTF-8 sequence. --- diff --git a/ext/json/JSON_parser.h b/ext/json/JSON_parser.h index 771ba967ac..746190bb35 100644 --- a/ext/json/JSON_parser.h +++ b/ext/json/JSON_parser.h @@ -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); diff --git a/ext/json/json.c b/ext/json/json.c index 5077dac562..7c21d33c9f 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -301,6 +301,7 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR 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"); } @@ -413,6 +414,7 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_DC) /* {{{ */ { + JSON_G(error_code) = PHP_JSON_ERROR_NONE; switch (Z_TYPE_P(val)) { case IS_NULL: