diff options
| author | Adam Harvey <aharvey@php.net> | 2010-09-16 13:53:27 +0000 |
|---|---|---|
| committer | Adam Harvey <aharvey@php.net> | 2010-09-16 13:53:27 +0000 |
| commit | 726fe638bb0a0f52ea899d18095a9d35297fa2af (patch) | |
| tree | 7b443da9b0db3feba32773d6bd6b579eb1081a0b /ext/json | |
| parent | aa297b60a3d53b2dfe076134ce9c066e4134399b (diff) | |
| download | php-git-726fe638bb0a0f52ea899d18095a9d35297fa2af.tar.gz | |
Implemented FR #49366 (Make slash escaping optional in json_encode()).
Diffstat (limited to 'ext/json')
| -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 |
3 files changed, 19 insertions, 1 deletions
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"" |
