Selaa lähdekoodia

ZF-9416
Applied patch for fixing Zend_Json_Encoder's incorrect handling of Iterator objects

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22452 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph 15 vuotta sitten
vanhempi
commit
7d4bced163
2 muutettua tiedostoa jossa 13 lisäystä ja 1 poistoa
  1. 1 1
      library/Zend/Json/Encoder.php
  2. 12 0
      tests/Zend/JsonTest.php

+ 1 - 1
library/Zend/Json/Encoder.php

@@ -145,7 +145,7 @@ class Zend_Json_Encoder
         foreach ($propCollection as $name => $propValue) {
             if (isset($propValue)) {
                 $props .= ','
-                        . $this->_encodeValue($name)
+                        . $this->_encodeString($name)
                         . ':'
                         . $this->_encodeValue($propValue);
             }

+ 12 - 0
tests/Zend/JsonTest.php

@@ -755,6 +755,18 @@ class Zend_JsonTest extends PHPUnit_Framework_TestCase
     {
         Zend_Json::decode(' some string ');
     }
+
+    /**
+     * @group ZF-9416
+     * Encoding an iterator using the internal encoder should handle undefined keys
+     */
+    public function testIteratorWithoutDefinedKey()
+    {
+        $inputValue = new ArrayIterator(array('foo'));
+        $encoded = Zend_Json_Encoder::encode($inputValue);
+        $expectedDecoding = '{"__className":"ArrayIterator","0":"foo"}';
+        $this->assertEquals($encoded, $expectedDecoding);
+    }
 }
 
 /**