]> granicus.if.org Git - php/commitdiff
MFH: Add error constant when json_encode detects an invalid UTF-8 sequence.
authorScott MacVicar <scottmac@php.net>
Mon, 27 Jul 2009 03:43:38 +0000 (03:43 +0000)
committerScott MacVicar <scottmac@php.net>
Mon, 27 Jul 2009 03:43:38 +0000 (03:43 +0000)
ext/json/JSON_parser.h
ext/json/json.c

index 771ba967ac3ac0d55073f864744d8490bcaa5afd..746190bb355701b3146b2aa67daf72b59e0f8f31 100644 (file)
@@ -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);
index 5077dac56218506bed7cb7c8b5b42a28a8119d1e..7c21d33c9f1cc091d1239cb27999647b7bc146d8 100644 (file)
@@ -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: