|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patch json_unescaped_unicode for JSON related Bug #53946Patch version 2011-08-29 12:57 UTC Return to Bug #53946 | Download this patchThis patch is obsolete Obsoleted by patches: This patch renders other patches obsolete Obsolete patches:
Developer: gwynne@php.net
Index: ext/json/json.c
===================================================================
--- ext/json/json.c (revision 315701)
+++ ext/json/json.c (working copy)
@@ -95,6 +95,7 @@
REGISTER_LONG_CONSTANT("JSON_NUMERIC_CHECK", PHP_JSON_NUMERIC_CHECK, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_UNESCAPED_SLASHES", PHP_JSON_UNESCAPED_SLASHES, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_PRETTY_PRINT", PHP_JSON_PRETTY_PRINT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("JSON_UNESCAPED_UNICODE", PHP_JSON_UNESCAPED_UNICODE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_ERROR_NONE", PHP_JSON_ERROR_NONE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_ERROR_DEPTH", PHP_JSON_ERROR_DEPTH, CONST_CS | CONST_PERSISTENT);
@@ -378,31 +379,32 @@
}
}
-
- utf16 = (unsigned short *) safe_emalloc(len, sizeof(unsigned short), 0);
-
- len = utf8_to_utf16(utf16, s, len);
- if (len <= 0) {
- if (utf16) {
- 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");
+
+ if (!(options & PHP_JSON_UNESCAPED_UNICODE)) {
+ utf16 = (unsigned short *) safe_emalloc(len, sizeof(unsigned short), 0);
+ len = utf8_to_utf16(utf16, s, len);
+ if (len <= 0) {
+ if (utf16) {
+ efree(utf16);
}
- smart_str_appendl(buf, "null", 4);
- } else {
- smart_str_appendl(buf, "\"\"", 2);
+ 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");
+ }
+ smart_str_appendl(buf, "null", 4);
+ } else {
+ smart_str_appendl(buf, "\"\"", 2);
+ }
+ return;
}
- return;
}
smart_str_appendc(buf, '"');
while (pos < len)
{
- us = utf16[pos++];
+ us = (options & PHP_JSON_UNESCAPED_UNICODE) ? s[pos++] : utf16[pos++];
switch (us)
{
@@ -479,7 +481,7 @@
break;
default:
- if (us >= ' ' && (us & 127) == us) {
+ if (us >= ' ' && ((options & PHP_JSON_UNESCAPED_UNICODE) || (us & 127) == us)) {
smart_str_appendc(buf, (unsigned char) us);
} else {
smart_str_appendl(buf, "\\u", 2);
@@ -498,7 +500,9 @@
}
smart_str_appendc(buf, '"');
- efree(utf16);
+ if (!(options & PHP_JSON_UNESCAPED_UNICODE)) {
+ efree(utf16);
+ }
}
/* }}} */
Index: ext/json/php_json.h
===================================================================
--- ext/json/php_json.h (revision 315701)
+++ ext/json/php_json.h (working copy)
@@ -62,6 +62,7 @@
#define PHP_JSON_NUMERIC_CHECK (1<<5)
#define PHP_JSON_UNESCAPED_SLASHES (1<<6)
#define PHP_JSON_PRETTY_PRINT (1<<7)
+#define PHP_JSON_UNESCAPED_UNICODE (1<<8)
/* Internal flags */
#define PHP_JSON_OUTPUT_ARRAY 0
|
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 09:00:01 2025 UTC |