Issues

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

Issue Type: Bug Created: 2011-05-17T22:32:51.000+0000 Last Updated: 2011-08-26T23:37:47.000+0000 Status: Resolved Fix version(s): - 1.11.7 (02/Jun/11)

Reporter: Edward Haber (ehaber) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Json

  • zf-crteam-padraic
  • zf-crteam-priority

Related issues: - ZF-3257

Attachments:

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.

<pre class="highlight">
$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:

<pre class="highlight">
Zend_Debug::dump($recursionDepth);
Zend_Debug::dump($simpleXmlElementObject);

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

Comments

Posted by Adam Lundrigan (adamlundrigan) on 2011-08-26T21:25:43.000+0000

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:

<pre class="highlight">
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

Posted by Adam Lundrigan (adamlundrigan) on 2011-08-26T21:55:32.000+0000

Committed tests in r24406 Merged to release-1.11 in r24407

Posted by Adam Lundrigan (adamlundrigan) on 2011-08-26T23:17:55.000+0000

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

Posted by Adam Lundrigan (adamlundrigan) on 2011-08-26T23:37:47.000+0000

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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts