Issues

ZF-11385: Zend_Json doesn't seem to count recursion correctly

Description

The following XML fragment has a nested depth of 6. It however throws a maxRecursion error ($maxRecursionDepthAllowed is set to 25). If I remove any one of the nodes below, it translates perfectly. So it is counting across nodes as well.


$body = <<success200 OKABCDEFGHABCDEABCDEABCABCD0.0790269374847
EOF;

header('Content-type', 'text/json');
echo Zend_Json::fromXml($body, true);

If I add these lines in _processXml to see what's going on:


Zend_Debug::dump($recursionDepth);
Zend_Debug::dump($simpleXmlElementObject);

... I find that it is counting every node laterally rather than by depth.

Comments

I was able to reproduce your issue against SVN tag release-1.11.6 using the XML you provided, but not against trunk. It appears that this issue was eliminated in 1.11.7 with the fix for ZF-3257 (fromXml functionality was rewritten).

Here are my tests, both of which pass:


Index: tests/Zend/Json/JsonXMLTest.php
===================================================================
--- tests/Zend/Json/JsonXMLTest.php     (revision 24405)
+++ tests/Zend/Json/JsonXMLTest.php     (working copy)
@@ -586,6 +586,74 @@

     }

+    /**
+     * @group ZF-11385
+     * @expectedException Zend_Json_Exception
+     * @dataProvider providerNestingDepthIsHandledProperly
+     */
+    public function testNestingDepthIsHandledProperlyWhenNestingDepthExceedsMaximum($xmlStringContents)
+    {
+        Zend_Json::$maxRecursionDepthAllowed = 1;
+        Zend_Json::fromXml($xmlStringContents, true);
+    }
+
+    /**
+     * @group ZF-11385
+     * @dataProvider providerNestingDepthIsHandledProperly
+     */
+    public function testNestingDepthIsHandledProperlyWhenNestingDepthDoesNotExceedMaximum($xmlStringContents)
+    {
+        Zend_Json::$maxRecursionDepthAllowed = 25;
+        Zend_Json::fromXml($xmlStringContents, true);
+    }
+
+    /**
+     * XML document provider for ZF-11385 tests
+     * @return array
+     */
+    public static function providerNestingDepthIsHandledProperly()
+    {
+        $xmlStringContents = <<
+       success
+       200 OK
+       
+               A
+               B
+               C
+               D
+               E
+               F
+               G
+               H
+               A
+               B
+               C
+               D
+               E
+               A
+               B
+               C
+               D
+               E
+               
+                       
+                               A
+                       
+                       B
+                       C
+                       A
+                       B
+                       C
+                       D
+               
+       
+       0.0790269374847
+
+EOT;
+        return array(array($xmlStringContents));
+    }
+
 } // End of class Zend_Json_JsonXMLTest

Committed tests in r24406 Merged to release-1.11 in r24407

Just realized that when I slimmed-down the XML, it kinda defeated the purpose of the tests. I've made it right. Merged updated tests to trunk in r24409 and release-1.11 in r24410

Issued ZF2 pull request PR-356 to have changes pulled forward