r80979 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80978‎ | r80979 | r80980 >
Date:19:00, 25 January 2011
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Resolves bug 26931, where comments were not only not being properly stripped out, but were being transformed into syntax errors.
Modified paths:
  • /trunk/phase3/includes/libs/JavaScriptDistiller.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/libs/JavaScriptDistiller.php
@@ -19,7 +19,6 @@
2020 * @param $stripVerticalSpace Boolean: Try to remove as much vertical whitespace as possible
2121 */
2222 public static function stripWhiteSpace( $script, $stripVerticalSpace = false ) {
23 - $script = self::stripComments( $script );
2423 $script = self::stripHorizontalSpace( $script );
2524 // If requested, make some vertical whitespace collapsing as well
2625 if ( $stripVerticalSpace ) {
@@ -29,15 +28,6 @@
3029 return $script;
3130 }
3231
33 - private static function stripComments( $script ) {
34 - $parser = self::createParser();
35 - // Remove comments
36 - $parser->add( '/\'([^\'\\\\]*(\\\\.[^\'\\\\]*)*)\'/', '$1' );
37 - $parser->add( '/"([^"\\\\]*(\\\\.[^"\\\\]*)*)"/', '$1' );
38 - // Execute and return
39 - return $parser->exec( $script );
40 - }
41 -
4232 private static function stripHorizontalSpace( $script ) {
4333 $parser = self::createParser();
4434 // Collapse horizontal whitespaces between variable names into a single space
@@ -92,6 +82,9 @@
9383 // Protect regular expressions
9484 $parser->add( '/[ \\t]+(\\/[^\\/\\r\\n\\*][^\\/\\r\\n]*\\/g?i?)/', '$2' );
9585 $parser->add( '/[^\\w\\$\\/\'"*)\\?:]\\/[^\\/\\r\\n\\*][^\\/\\r\\n]*\\/g?i?/', '$1' );
 86+ // Remove comments
 87+ $parser->add( '/\\/\\*(.|[\\r\\n])*?\\*\\//' );
 88+ $parser->add( '/\\/\\/[^\\r\\n]*[\\r\\n]/' );
9689 return $parser;
9790 }
9891 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r810001.17: MFT r80576, r80583, r80656, r80842, r80900, r80913, r80918, r80919, r80...catrope22:49, 25 January 2011

Comments

#Comment by Nikerabbit (talk | contribs)   22:25, 25 January 2011

Can we add tests for this?

#Comment by Trevor Parscal (WMF) (talk | contribs)   22:27, 25 January 2011

Sure - this would be a great thing to write unit tests for...

Status & tagging log