From 1607e9fa79f6270345a320006fa79c1833ba6dc1 Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Mon, 23 Apr 2007 10:48:13 +0000 Subject: [PATCH] MFB fix for #41034 add missing tests --- ext/json/json.c | 2 +- ext/json/tests/002.phpt | 2 +- ext/json/tests/bug41034.phpt | 12 ++++++++++++ ext/json/tests/bug41067.phpt | 23 +++++++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 ext/json/tests/bug41034.phpt create mode 100644 ext/json/tests/bug41067.phpt diff --git a/ext/json/json.c b/ext/json/json.c index cb6f947667..53f4bb523c 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -176,7 +176,7 @@ static void json_encode_array(smart_str *buf, zval **val TSRMLS_DC) /* {{{ */ } else if (r == 1) { if (i == HASH_KEY_IS_STRING || i == HASH_KEY_IS_UNICODE) { - if (key.s[0] == '\0') { + if (key.s[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..cc7704122d --- /dev/null +++ b/ext/json/tests/bug41034.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #41034 (json_encode() ignores null byte started keys in arrays) +--SKIPIF-- + +--FILE-- +1,"\0null-prefixed value")); +echo "\nDone\n"; +?> +--EXPECT-- +{"0":0,"\u0000ab":1,"1":"\u0000null-prefixed value"} +Done diff --git a/ext/json/tests/bug41067.phpt b/ext/json/tests/bug41067.phpt new file mode 100644 index 0000000000..e3bcb76f7f --- /dev/null +++ b/ext/json/tests/bug41067.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #41067 (json_encode() problem with UTF-16 input) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +string(8) "f09d8480" +string(8) "f09d8480" +--UEXPECT-- +unicode(8) "f09d8480" +unicode(8) "f09d8480" -- 2.40.0