Kaynağa Gözat

ZF-7586: Zend_Json_Decoder emits fatal error when decoding JSON string with empty key

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24799 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 yıl önce
ebeveyn
işleme
c742281785
2 değiştirilmiş dosya ile 16 ekleme ve 0 silme
  1. 3 0
      library/Zend/Json/Decoder.php
  2. 13 0
      tests/Zend/JsonTest.php

+ 3 - 0
library/Zend/Json/Decoder.php

@@ -236,6 +236,9 @@ class Zend_Json_Decoder
                 // Create new StdClass and populate with $members
                 $result = new StdClass();
                 foreach ($members as $key => $value) {
+                    if ($key === '') {
+                        $key = '_empty_';
+                    }
                     $result->$key = $value;
                 }
                 break;

+ 13 - 0
tests/Zend/JsonTest.php

@@ -888,6 +888,19 @@ EOB;
         $json = Zend_Json::encode($array);
         $this->assertEquals($expected, $json);
     }
+    
+    /**
+     * @group ZF-7586
+     */
+    public function testWillDecodeStructureWithEmptyKeyToObjectProperly()
+    {
+        Zend_Json::$useBuiltinEncoderDecoder = true;
+        
+        $json = '{"":"test"}';
+        $object = Zend_Json::decode($json, Zend_Json::TYPE_OBJECT);
+        $this->assertTrue(isset($object->_empty_));
+        $this->assertEquals('test', $object->_empty_);
+    }
 
 }