Tim Starling has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/153573

Change subject: In minifier, preserve comments that start with /*!
......................................................................

In minifier, preserve comments that start with /*!

Like jQuery. As requested by Mako in comment 14 of the linked bug.
To resolve the bug, such comments should be added to all our files.

Bug: 36866
Change-Id: Ia2ab0d91f0cb739f183ca6b3f0eb1a49f14655f0
---
M includes/libs/JavaScriptMinifier.php
M tests/phpunit/includes/libs/JavaScriptMinifierTest.php
2 files changed, 11 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/73/153573/1

diff --git a/includes/libs/JavaScriptMinifier.php 
b/includes/libs/JavaScriptMinifier.php
index 2990782..2b0adf3 100644
--- a/includes/libs/JavaScriptMinifier.php
+++ b/includes/libs/JavaScriptMinifier.php
@@ -426,9 +426,13 @@
                        // First, skip over any whitespace and multiline 
comments, recording whether we
                        // found any newline character
                        $skip = strspn( $s, " \t\n\r\xb\xc", $pos );
+                       $licenseComment = false;
                        if( !$skip ) {
                                $ch = $s[$pos];
                                if( $ch === '/' && substr( $s, $pos, 2 ) === 
'/*' ) {
+                                       if ( substr( $s, $pos, 3 ) == '/*!' ) {
+                                               $licenseComment = true;
+                                       }
                                        // Multiline comment. Search for the 
end token or EOT.
                                        $end = strpos( $s, '*/', $pos + 2 );
                                        $skip = $end === false ? $length - $pos 
: $end - $pos + 2;
@@ -440,6 +444,10 @@
                                if( !$newlineFound && strcspn( $s, "\r\n", 
$pos, $skip ) !== $skip ) {
                                        $newlineFound = true;
                                }
+                               if ( $licenseComment ) {
+                                       // Preserve jQuery-style license 
comments
+                                       $out .= substr( $s, $pos, $skip );
+                               }
                                $pos += $skip;
                                continue;
                        }
diff --git a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php 
b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php
index c8795b2..f690eda 100644
--- a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php
+++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php
@@ -9,6 +9,9 @@
                        array( "\r\t\f \v\n\r", "" ),
                        array( "/* Foo *\n*bar\n*/", "" ),
 
+                       // License comments should be preserved
+                       array( "/*!foo*//*bar*/", "/*!foo*/" ),
+
                        /**
                         * Slashes used inside block comments (bug 26931).
                         * At some point there was a bug that caused this 
comment to be ended at '* /',

-- 
To view, visit https://gerrit.wikimedia.org/r/153573
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia2ab0d91f0cb739f183ca6b3f0eb1a49f14655f0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Tim Starling <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to