rasmus                                   Wed, 22 Jul 2009 21:32:58 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=284625

Log:
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.

Changed paths:
    U   php/php-src/trunk/ext/json/JSON_parser.h
    U   php/php-src/trunk/ext/json/json.c

Modified: php/php-src/trunk/ext/json/JSON_parser.h
===================================================================
--- php/php-src/trunk/ext/json/JSON_parser.h    2009-07-22 20:21:39 UTC (rev 
284624)
+++ php/php-src/trunk/ext/json/JSON_parser.h    2009-07-22 21:32:58 UTC (rev 
284625)
@@ -24,6 +24,7 @@
     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);

Modified: php/php-src/trunk/ext/json/json.c
===================================================================
--- php/php-src/trunk/ext/json/json.c   2009-07-22 20:21:39 UTC (rev 284624)
+++ php/php-src/trunk/ext/json/json.c   2009-07-22 21:32:58 UTC (rev 284625)
@@ -93,6 +93,7 @@
        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 @@
                                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 @@
                        if (utf16) {
                                efree(utf16);
                        }
+                       JSON_G(error_code) = PHP_JSON_ERROR_UTF8;
                        RETURN_NULL();
                }
        }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to