Issues

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

Issue Type: Bug Created: 2010-10-27T11:50:55.000+0000 Last Updated: 2011-07-28T19:28:43.000+0000 Status: Resolved Fix version(s): - 1.11.6 (05/May/11)

Reporter: Marcin Wójcik (zeulus) Assignee: Robert Basic (robertbasic) Tags: - Zend_Dojo

Related issues: - ZF-9165

Attachments: - ZF-10604.diff

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

Posted by Matthew Weier O'Phinney (matthew) on 2010-10-27T11:56:40.000+0000

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

Posted by Marcin Wójcik (zeulus) on 2010-10-27T13:56:26.000+0000

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 .= ';'; }

Posted by Marcin Wójcik (zeulus) on 2010-10-27T14:26:38.000+0000

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

<pre class="literal">

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 .= ';';
         } 

Posted by Robert Basic (robertbasic) on 2011-04-23T15:40:26.000+0000

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

Posted by Marcin Wójcik (zeulus) on 2011-04-25T09:41:51.000+0000

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

Posted by Robert Basic (robertbasic) on 2011-04-28T22:31:01.000+0000

Fixed in r23880 in trunk.

Posted by Robert Basic (robertbasic) on 2011-04-29T21:47:45.000+0000

Fixed in r23893 in release branch 1.11

Posted by Robert Basic (robertbasic) on 2011-07-28T19:28:43.000+0000

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

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