From faae3e9ecf55bbdb2d0f217016e8b59114b58f4c Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Sun, 27 May 2007 16:31:35 +0000 Subject: Fixed bug #41504 (json_decode() incorrectly decodes JSON arrays with empty string keys). --- ext/json/JSON_parser.c | 6 +++--- ext/json/tests/bug41504.phpt | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 ext/json/tests/bug41504.phpt (limited to 'ext/json') diff --git a/ext/json/JSON_parser.c b/ext/json/JSON_parser.c index 91f565e033..2f2d268125 100644 --- a/ext/json/JSON_parser.c +++ b/ext/json/JSON_parser.c @@ -364,7 +364,7 @@ static void attach_zval(json_parser *json, int up, int cur, smart_str *key, int } else { - add_assoc_zval_ex(root, (key->len ? key->c : "_empty_"), (key->len ? (key->len + 1) : sizeof("_empty_")), child); + add_assoc_zval_ex(root, (key->len ? key->c : ""), (key->len ? (key->len + 1) : sizeof("")), child); } key->len = 0; } @@ -507,7 +507,7 @@ JSON_parser(zval *z, unsigned short p[], int length, int assoc TSRMLS_DC) } else { - add_assoc_zval_ex(JSON(the_zstack)[JSON(the_top)], (key.len ? key.c : "_empty_"), (key.len ? (key.len + 1) : sizeof("_empty_")), mval); + add_assoc_zval_ex(JSON(the_zstack)[JSON(the_top)], (key.len ? key.c : ""), (key.len ? (key.len + 1) : sizeof("")), mval); } key.len = 0; buf.len = 0; @@ -638,7 +638,7 @@ JSON_parser(zval *z, unsigned short p[], int length, int assoc TSRMLS_DC) } else { - add_assoc_zval_ex(JSON(the_zstack)[JSON(the_top)], (key.len ? key.c : "_empty_"), (key.len ? (key.len + 1) : sizeof("_empty_")), mval); + add_assoc_zval_ex(JSON(the_zstack)[JSON(the_top)], (key.len ? key.c : ""), (key.len ? (key.len + 1) : sizeof("")), mval); } key.len = 0; } diff --git a/ext/json/tests/bug41504.phpt b/ext/json/tests/bug41504.phpt new file mode 100644 index 0000000000..6e51bb91a9 --- /dev/null +++ b/ext/json/tests/bug41504.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #41504 (json_decode() converts empty array keys to "_empty_") +--FILE-- + +--EXPECT-- +array(1) { + [""]=> + string(5) "value" +} +array(2) { + [""]=> + string(5) "value" + ["key"]=> + string(5) "value" +} +array(2) { + ["key"]=> + string(5) "value" + [""]=> + string(5) "value" +} +Done \ No newline at end of file -- cgit v1.2.1