]> 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 3c20498aa8392eb9881a5455d4d5b4bad78efb60..c7759ed740b4e544ef96cf112c83639f2627de87 100644 (file)
@@ -297,7 +297,7 @@ static void json_encode_array(smart_str *buf, zval **val, int options TSRMLS_DC)
 
                                                json_pretty_print_indent(buf, options TSRMLS_CC);
 
-                                               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, ':');
 
                                                json_pretty_print_char(buf, 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}"