diff options
-rw-r--r-- | NEWS | 1 | ||||
-rwxr-xr-x | UPGRADING | 2 | ||||
-rw-r--r-- | ext/json/json.c | 7 | ||||
-rw-r--r-- | ext/json/php_json.h | 1 | ||||
-rw-r--r-- | ext/json/tests/json_encode_unescaped_slashes.phpt | 12 |
5 files changed, 21 insertions, 2 deletions
@@ -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, @@ -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-- +<?php if (!extension_loaded("json")) print "skip"; ?> +--FILE-- +<?php +var_dump(json_encode('a/b')); +var_dump(json_encode('a/b', JSON_UNESCAPED_SLASHES)); +?> +--EXPECT-- +string(6) ""a\/b"" +string(5) ""a/b"" |