Details
-
Bug
-
Resolution: Unresolved
-
Medium
-
None
-
None
-
None
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
Issue Links
- relates to
-
EZP-18317 ezscript, with default compress drops some js code
- Closed