Resolves bug 26931, where comments were not only not being properly stripped out...
authorTrevor Parscal <tparscal@users.mediawiki.org>
Tue, 25 Jan 2011 19:00:21 +0000 (19:00 +0000)
committerTrevor Parscal <tparscal@users.mediawiki.org>
Tue, 25 Jan 2011 19:00:21 +0000 (19:00 +0000)
includes/libs/JavaScriptDistiller.php

index c15d870..358827f 100644 (file)
@@ -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;
        }
 }