]> granicus.if.org Git - php/commitdiff
MFB fix for #41034
authorAntony Dovgal <tony2001@php.net>
Mon, 23 Apr 2007 10:48:13 +0000 (10:48 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 23 Apr 2007 10:48:13 +0000 (10:48 +0000)
add missing tests

ext/json/json.c
ext/json/tests/002.phpt
ext/json/tests/bug41034.phpt [new file with mode: 0644]
ext/json/tests/bug41067.phpt [new file with mode: 0644]

index cb6f947667d29981c76e0ceca6acf3f3d24c1176..53f4bb523cabb735960cbeba3c62f9c6a62d98a9 100644 (file)
@@ -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;
                         }
index 5bc29bc5b9598442aed518e60429688cdc921e21..87f57421f3c9c3416fdc6c51c4c1d85da3bedaff 100644 (file)
@@ -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 (file)
index 0000000..cc77041
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #41034 (json_encode() ignores null byte started keys in arrays)
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?php
+echo json_encode(array(0,"\0ab"=>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 (file)
index 0000000..e3bcb76
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Bug #41067 (json_encode() problem with UTF-16 input)
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?php
+
+$single_barline = "\360\235\204\200";
+$array = array($single_barline);
+var_dump(bin2hex((binary)$single_barline));
+
+$json = json_encode($array);
+$json_decoded = json_decode($json, true);
+
+var_dump(bin2hex((binary)$json_decoded[0]));
+
+?>
+--EXPECT--
+string(8) "f09d8480"
+string(8) "f09d8480"
+--UEXPECT--
+unicode(8) "f09d8480"
+unicode(8) "f09d8480"