Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-19256

eZ JS packer should insert semicolons as needed



    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Affects Version/s: 4.6.0
    • Fix Version/s: None
    • Labels:
    • Environment:

      Operating System: Ubuntu
      PHP Version: 5.2.11-0.dotdeb.0 with Suhosin-Patch 0.9.7
      Database and version: MySQL 5.0
      Browser (and version): Firefox 10.0.2


      I just upgraded a site to eZP 4.6 from 4.5, and ended up with an admin interface that didn't display any children on the content tab unless DevelopmentMode was enabled.

      I tracked this down to a strange JavaScript error ("eval(....) is not a function"), which I then tracked down to a JS file in one of the extensions on the site - or rather, the error lay in the edge between two such files when processed by the packer.

      The first JS file was already packed, and didn't end its last (and only) statement in a semicolon - which is perfectly valid JavaScript, as the end of the line often ends statements (and this file held only comments between that statement and the end of the file, which is a rather effective statement terminator).

      The next JS file started (after a comment) with a parenthesis (the typical namespacing function).

      In separate files, this works perfectly, but the JS packer removed all the comments and blank lines, putting these two lines right after each other, with no semicolon in between - which caused Firefox to treat the second line as parameters to the first, and complained because the first didn't return a function.

      Hence, I think the packer should insert semicolons between the JS files it combines, so as to maintain the separation between the statements of those files.

      It could avoid adding this semicolon if the previous file already ends in one, but it is probably easier to just always add one, as empty statements are perfectly legal, and a subsequent minifier class can remove extra semicolons much easier than it can insert new ones after the content is already one long string.

      This can be done by adding this line after line 456 in ezjscpacker.php:

      if ( !$isCSS ) $content .= ';';

      In my case, I could modify the extension with the first file (since it happened to be one of ours, even though the JS file is from elsewhere), so I added a semicolon to the end of the file, which fixed the problem for me - this time. Next time I might not be as lucky...

      Steps to reproduce

      On eZ Publish 4.6, set up an extension with two JavaScript files, and make sure both are included into the admin2 design (e.g. using JavaScriptList[] in design.ini).

      In the first file, put a statement that could conceivably return a function, and don't terminate it with a semicolon.

      In the second file, put a standard namespacing function construct (like this: "(function()

      { /* code here */ }


      Set DevelopmentMode to disabled, and clear the caches.

      Load a content node with children. See that it gives the number of them, but never even starts to load the list. The Error Console shows an error about the first line not being a function.

      Set DevelopmentMode to enabled, and clear the caches.

      Reload the content node. See that it now loads the list of children like it is supposed to, and no error appears in the error console.




            unknown unknown
            edorfaus Frode Austvik
            0 Vote for this issue
            1 Start watching this issue