From: Trevor Parscal Date: Tue, 25 Jan 2011 19:00:21 +0000 (+0000) Subject: Resolves bug 26931, where comments were not only not being properly stripped out... X-Git-Tag: 1.31.0-rc.0~32367 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=8d36f308020a403d2afc97bea7eefa11d086a0dc;p=lhc%2Fweb%2Fwiklou.git Resolves bug 26931, where comments were not only not being properly stripped out, but were being transformed into syntax errors. --- diff --git a/includes/libs/JavaScriptDistiller.php b/includes/libs/JavaScriptDistiller.php index c15d870c51..358827ffe6 100644 --- a/includes/libs/JavaScriptDistiller.php +++ b/includes/libs/JavaScriptDistiller.php @@ -19,7 +19,6 @@ class JavaScriptDistiller { * @param $stripVerticalSpace Boolean: Try to remove as much vertical whitespace as possible */ public static function stripWhiteSpace( $script, $stripVerticalSpace = false ) { - $script = self::stripComments( $script ); $script = self::stripHorizontalSpace( $script ); // If requested, make some vertical whitespace collapsing as well if ( $stripVerticalSpace ) { @@ -29,15 +28,6 @@ class JavaScriptDistiller { return $script; } - private static function stripComments( $script ) { - $parser = self::createParser(); - // Remove comments - $parser->add( '/\'([^\'\\\\]*(\\\\.[^\'\\\\]*)*)\'/', '$1' ); - $parser->add( '/"([^"\\\\]*(\\\\.[^"\\\\]*)*)"/', '$1' ); - // Execute and return - return $parser->exec( $script ); - } - private static function stripHorizontalSpace( $script ) { $parser = self::createParser(); // Collapse horizontal whitespaces between variable names into a single space @@ -92,6 +82,9 @@ class JavaScriptDistiller { // Protect regular expressions $parser->add( '/[ \\t]+(\\/[^\\/\\r\\n\\*][^\\/\\r\\n]*\\/g?i?)/', '$2' ); $parser->add( '/[^\\w\\$\\/\'"*)\\?:]\\/[^\\/\\r\\n\\*][^\\/\\r\\n]*\\/g?i?/', '$1' ); + // Remove comments + $parser->add( '/\\/\\*(.|[\\r\\n])*?\\*\\//' ); + $parser->add( '/\\/\\/[^\\r\\n]*[\\r\\n]/' ); return $parser; } }