From: Ilia Alshanetsky Date: Thu, 12 Apr 2007 19:40:38 +0000 (+0000) Subject: Fixed bug #41034 (json_encode() ignores null byte started keys in arrays) X-Git-Tag: php-5.2.2RC2~103 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a133297c86c23b72d11ea7cb18dfe294d7714f05;p=php Fixed bug #41034 (json_encode() ignores null byte started keys in arrays) --- diff --git a/NEWS b/NEWS index 67da13e199..6a44880d83 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ PHP NEWS - Fixed bug #41063 (chdir doesn't like root paths). (Dmitry) - Fixed bug #41061 ("visibility error" in ReflectionFunction::export()). (Johannes) +- Fixed bug #41034 (json_encode() ignores null byte started keys in arrays). + (Ilia) - Fixed bug #40861 (strtotime() doesn't handle double negative relative time units correctly). (Derick) diff --git a/ext/json/json.c b/ext/json/json.c index 1bfe3e0743..809d005c57 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -177,7 +177,7 @@ static void json_encode_array(smart_str *buf, zval **val TSRMLS_DC) { json_encode_r(buf, *data TSRMLS_CC); } else if (r == 1) { if (i == HASH_KEY_IS_STRING) { - if (key[0] == '\0') { + if (key[0] == '\0' && Z_TYPE_PP(val) == IS_OBJECT) { /* Skip protected and private members. */ continue; } diff --git a/ext/json/tests/002.phpt b/ext/json/tests/002.phpt index 5bc29bc5b9..87f57421f3 100644 --- a/ext/json/tests/002.phpt +++ b/ext/json/tests/002.phpt @@ -21,7 +21,7 @@ echo "Done\n"; string(2) """" string(4) "null" string(4) "true" -string(2) "{}" +string(7) "{"":""}" string(5) "[[1]]" string(1) "1" string(38) ""\u0440\u0443\u0441\u0441\u0438\u0448"" diff --git a/ext/json/tests/bug41034.phpt b/ext/json/tests/bug41034.phpt new file mode 100644 index 0000000000..7a7e5f758a Binary files /dev/null and b/ext/json/tests/bug41034.phpt differ