Issues

ZF-10604: Zend_Dojo container's addJavascript() returns empty string because of preg_match() when long js string provided

Description

I've found problem that occurs when making complicated forms with 200+ dijits (in my case mostly checkboxes and radios). When zendDijits string is relatively short addJavascript() returns proper json encoded js, but when it exceeds certain size it returns null and whole form is broken (JS error: zendDijits is not defined). It's the same problem that was described in issue ZF-6383.

The very same problem existed in ZendX_JQuery and it was solved in ZF-8011.

Any chances to fix it in upcoming ZF 1.11?

Best regards

Comments

No, but we can resolve it for 1.11.1. Any chance you can provide a patch?

I've added simple trimming default whitespaces, that should be enough.

Patch:

Index: library/Zend/Dojo/View/Helper/Dojo/Container.php

--- library/Zend/Dojo/View/Helper/Dojo/Container.php (revision 23263) +++ library/Zend/Dojo/View/Helper/Dojo/Container.php (working copy) @@ -882,7 +882,7 @@ / public function addJavascript($js) { - $js = preg_replace('/^\s(.?)\s$/s', '$1', $js); + $js = trim($js); if (!in_array(substr($js, -1), array(';', '}'))) { $js .= ';'; }

Sorry, I've just noticed that patch code is malformed... is there any way to attach file?


Index: library/Zend/Dojo/View/Helper/Dojo/Container.php
===================================================================
--- library/Zend/Dojo/View/Helper/Dojo/Container.php    (revision 23263)
+++ library/Zend/Dojo/View/Helper/Dojo/Container.php    (working copy)
@@ -882,7 +882,7 @@
      */
     public function addJavascript($js)
     {
-        $js = preg_replace('/^\s*(.*?)\s*$/s', '$1', $js);
+        $js = trim($js);
         if (!in_array(substr($js, -1), array(';', '}'))) {
             $js .= ';';
         } 

Created a patch file as per Marcin's comments/instructions.

Thanks, Robert. I just don't see any option here to add attachment - how could I do that?

Fixed in r23880 in trunk.

Fixed in r23893 in release branch 1.11

A pull request to import the patch to ZF2 is sent https://github.com/zendframework/zf2/pull/288