summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
authorJakub Zelenka <bukka@php.net>2017-10-15 19:36:15 +0100
committerJakub Zelenka <bukka@php.net>2017-10-15 19:36:15 +0100
commit7c556c44a10bfc53c37295626e61bd99dc4f550c (patch)
tree77b2135977afe6e62af51f710b57a5e632cb55eb /ext/json
parent46d87c1f104261331a3fa33208f2da4d92c59225 (diff)
downloadphp-git-7c556c44a10bfc53c37295626e61bd99dc4f550c.tar.gz
Fix bug #68567 (JSON_PARTIAL_OUTPUT_ON_ERROR can result in JSON with null key)
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/json_encoder.c9
-rw-r--r--ext/json/tests/bug68567.phpt14
2 files changed, 21 insertions, 2 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
index 1fa2344204..fcdb315954 100644
--- a/ext/json/json_encoder.c
+++ b/ext/json/json_encoder.c
@@ -189,8 +189,13 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso
php_json_pretty_print_char(buf, options, '\n');
php_json_pretty_print_indent(buf, options, encoder);
- php_json_escape_string(buf, ZSTR_VAL(key), ZSTR_LEN(key),
- options & ~PHP_JSON_NUMERIC_CHECK, encoder);
+ if (php_json_escape_string(buf, ZSTR_VAL(key), ZSTR_LEN(key),
+ options & ~PHP_JSON_NUMERIC_CHECK, encoder) == FAILURE &&
+ (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) &&
+ buf->s) {
+ ZSTR_LEN(buf->s) -= 4;
+ smart_str_appendl(buf, "\"\"", 2);
+ }
} else {
if (need_comma) {
smart_str_appendc(buf, ',');
diff --git a/ext/json/tests/bug68567.phpt b/ext/json/tests/bug68567.phpt
new file mode 100644
index 0000000000..6d4082c2b7
--- /dev/null
+++ b/ext/json/tests/bug68567.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Bug #68567 JSON_PARTIAL_OUTPUT_ON_ERROR can result in JSON with null key
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(json_encode(array("\x80" => 1), JSON_PARTIAL_OUTPUT_ON_ERROR));
+
+?>
+===DONE===
+--EXPECTF--
+string(6) "{"":1}"
+===DONE===