From: Adam Harvey Date: Thu, 16 Sep 2010 13:53:27 +0000 (+0000) Subject: Implemented FR #49366 (Make slash escaping optional in json_encode()). X-Git-Tag: php-5.4.0alpha1~191^2~936 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=726fe638bb0a0f52ea899d18095a9d35297fa2af;p=php Implemented FR #49366 (Make slash escaping optional in json_encode()). --- diff --git a/NEWS b/NEWS index c6ce838f69..da8139e64c 100644 --- a/NEWS +++ b/NEWS @@ -118,6 +118,7 @@ - Implemented FR #52555 (Ability to get HTTP response code). (Paul Dragoonis) - Implemented FR #51295 (SQLite3::busyTimeout not existing). (Mark) +- Implemented FR #49366 (Make slash escaping optional in json_encode()). (Adam) - Implemented FR #48632 (OpenSSL AES support). (yonas dot y at gmail dot com, Pierre) - Implemented FR #42060 (Add paged Results support). (ando@OpenLDAP.org, diff --git a/UPGRADING b/UPGRADING index 9a31cbd630..11cbaa5a52 100755 --- a/UPGRADING +++ b/UPGRADING @@ -235,7 +235,7 @@ UPGRADE NOTES - PHP X.Y f. New global constants - - + - JSON_UNESCAPED_SLASHES g. New classes diff --git a/ext/json/json.c b/ext/json/json.c index c81c05d587..3e893f0e8d 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -92,6 +92,7 @@ static PHP_MINIT_FUNCTION(json) REGISTER_LONG_CONSTANT("JSON_HEX_QUOT", PHP_JSON_HEX_QUOT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("JSON_FORCE_OBJECT", PHP_JSON_FORCE_OBJECT, CONST_CS | CONST_PERSISTENT); 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_ERROR_NONE", PHP_JSON_ERROR_NONE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("JSON_ERROR_DEPTH", PHP_JSON_ERROR_DEPTH, CONST_CS | CONST_PERSISTENT); @@ -372,7 +373,11 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR break; case '/': - smart_str_appendl(buf, "\\/", 2); + if (options & PHP_JSON_UNESCAPED_SLASHES) { + smart_str_appendc(buf, '/'); + } else { + smart_str_appendl(buf, "\\/", 2); + } break; case '\b': diff --git a/ext/json/php_json.h b/ext/json/php_json.h index fd5287c0e5..c321ad292a 100644 --- a/ext/json/php_json.h +++ b/ext/json/php_json.h @@ -59,6 +59,7 @@ extern zend_class_entry *php_json_serializable_ce; #define PHP_JSON_HEX_QUOT (1<<3) #define PHP_JSON_FORCE_OBJECT (1<<4) #define PHP_JSON_NUMERIC_CHECK (1<<5) +#define PHP_JSON_UNESCAPED_SLASHES (1<<6) /* Internal flags */ #define PHP_JSON_OUTPUT_ARRAY 0 diff --git a/ext/json/tests/json_encode_unescaped_slashes.phpt b/ext/json/tests/json_encode_unescaped_slashes.phpt new file mode 100644 index 0000000000..72ebae927a --- /dev/null +++ b/ext/json/tests/json_encode_unescaped_slashes.phpt @@ -0,0 +1,12 @@ +--TEST-- +json_decode() tests +--SKIPIF-- + +--FILE-- + +--EXPECT-- +string(6) ""a\/b"" +string(5) ""a/b""