From 8d36f308020a403d2afc97bea7eefa11d086a0dc Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Tue, 25 Jan 2011 19:00:21 +0000 Subject: [PATCH] Resolves bug 26931, where comments were not only not being properly stripped out, but were being transformed into syntax errors. --- includes/libs/JavaScriptDistiller.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) 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; } } -- 2.20.1