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

ezjscore JS optimizer breaks JS with mixed single and multiline comments

    XMLWordPrintable

Details

    Description

      JS using code like:

      var bar = 'foo';
      /*
      Some
      commented
      lines
      // var baz = 'test';*/
      var foo = 'bar';
      

      Will be optimized as:

      var bar = 'foo';
      

      instead of:

      var bar = 'foo';var foo = 'bar';
      

      The reason is that the end of the multiline comment appears on a single line comment.

      The following patch solves the issue:

      diff --git classes/ezjscjavascriptoptimizer.php classes/ezjscjavascriptoptimizer.php
      index 0e38835d85c3d68ff9a0b90ca7a3527d1094ef12..efc02c86cf25e50ad9a2743abdadead9480e5b48 100644
      --- classes/ezjscjavascriptoptimizer.php
      +++ classes/ezjscjavascriptoptimizer.php
      @@ -42,13 +42,13 @@ class ezjscJavascriptOptimizer
               // Normalize line feeds
               $script = str_replace( array( "\r\n", "\r" ), "\n", $script );
       
      -        // Remove whitespace from start & end of line + singelline comment + multiple linefeeds
      -        $script = preg_replace( array( '/\n\s+/', '/\s+\n/', '#\n\s*//.*#', '/\n+/' ), "\n", $script );
      -
               // Remove multiline comments
               $script = preg_replace( '!(?:\n|\s|^)/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $script );
               $script = preg_replace( '!(?:;)/\*[^*]*\*+([^/][^*]*\*+)*/!', ';', $script );
       
      +        // Remove whitespace from start & end of line + singelline comment + multiple linefeeds
      +        $script = preg_replace( array( '/\n\s+/', '/\s+\n/', '#\n\s*//.*#', '/\n+/' ), "\n", $script );
      +
               return $script;
           }
       }
      

      Attachments

        Activity

          People

            e8318ba6-e4ae-477c-9116-36c073bd11a3@accounts.ibexa.co Patrick Allaert
            e8318ba6-e4ae-477c-9116-36c073bd11a3@accounts.ibexa.co Patrick Allaert
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: