]> granicus.if.org Git - php/commitdiff
Fixed bug #55543 (json_encode() with JSON_NUMERIC_CHECK fails on objects with numeric...
authorIlia Alshanetsky <iliaa@php.net>
Mon, 17 Oct 2011 23:51:25 +0000 (23:51 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 17 Oct 2011 23:51:25 +0000 (23:51 +0000)
ext/json/json.c
ext/json/tests/bug55543.phpt [new file with mode: 0644]

index 4e8fd759d45d2ba8a6e4884d54389f2eb8df0c89..62d20caadf403bf026fe6aa0025061a0eb0d084c 100644 (file)
@@ -238,7 +238,7 @@ static void json_encode_array(smart_str *buf, zval **val, int options TSRMLS_DC)
                                                        need_comma = 1;
                                                }
 
-                                               json_escape_string(buf, key, key_len - 1, options TSRMLS_CC);
+                                               json_escape_string(buf, key, key_len - 1, options & ~PHP_JSON_NUMERIC_CHECK TSRMLS_CC);
                                                smart_str_appendc(buf, ':');
 
                                                php_json_encode(buf, *data, options TSRMLS_CC);
diff --git a/ext/json/tests/bug55543.phpt b/ext/json/tests/bug55543.phpt
new file mode 100644 (file)
index 0000000..8657fe7
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Bug #55543 (json_encode() with JSON_NUMERIC_CHECK & numeric string properties)
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?php
+$a = new stdClass;
+$a->{"1"} = "5";
+
+var_dump(json_encode($a, JSON_NUMERIC_CHECK));
+?>
+--EXPECT--
+string(7) "{"1":5}"