Revert r103978, r103979 -- screwed something up, breaks jQuery minification.
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 23 Nov 2011 00:22:46 +0000 (00:22 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 23 Nov 2011 00:22:46 +0000 (00:22 +0000)
Incremented ResourceLoader::filterCacheVersion rather than decrementing to avoid potential confusion, especially since we already needed the incr.

includes/libs/JavaScriptMinifier.php
includes/resourceloader/ResourceLoader.php
tests/phpunit/includes/libs/JavaScriptMinifierTest.php

index 976c02f..baf9338 100644 (file)
@@ -498,17 +498,19 @@ class JavaScriptMinifier {
                                ctype_digit( $ch )
                                || ( $ch === '.' && $pos + 1 < $length && ctype_digit( $s[$pos + 1] ) )
                        ) {
-                               $end += strspn( $s, '0123456789', $end, 1 );
+                               $end += strspn( $s, '0123456789', $end );
                                $decimal = strspn( $s, '.', $end );
                                if ($decimal) {
-                                       // If there are multiple decimal points, we only deal with the first one.
-                                       // A following identifier is illegitimate after a raw . but a . and a property? Legit.
-                                       // @fixme elsewhere in the code, if we find an identifier right after this - throw a parse error
-                                       $end++;
-                                       $end += strspn( $s, '0123456789', $end );
+                                       if ( $decimal > 2 ) {
+                                               return self::parseError($s, $end, 'The number has too many decimal points' );
+                                       }
+                                       $end += strspn( $s, '0123456789', $end + 1 ) + $decimal;
                                }
-                               $exponent = strspn( $s, 'eE', $end, 1 );
+                               $exponent = strspn( $s, 'eE', $end );
                                if( $exponent ) {
+                                       if ( $exponent > 1 ) {
+                                               return self::parseError($s, $end, 'Number with several E' );
+                                       }
                                        $end++;
                                        
                                        // + sign is optional; - sign is required.
index f64cef7..ac62cb0 100644 (file)
@@ -29,7 +29,7 @@
 class ResourceLoader {
 
        /* Protected Static Members */
-       protected static $filterCacheVersion = 6;
+       protected static $filterCacheVersion = 7;
        protected static $requiredSourceProperties = array( 'loadScript' );
 
        /** Array: List of module name/ResourceLoaderModule object pairs */
index d7d3cf4..d2bfeed 100644 (file)
@@ -89,14 +89,8 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
                        array( "var a = 5.;", "var a=5.;" ),
                        array( "5.0.toString();", "5.0.toString();" ),
                        array( "5..toString();", "5..toString();" ),
+                       array( "5...toString();", false ),
                        array( "5.\n.toString();", '5..toString();' ),
-
-                       /* Some structures that are invalid, that we may not detect */
-                       //array( "5...toString();", false ), // can't detect this yet, though JSParser will throw error
-                       array( '5e1', '5e1' ),
-                       array( "5e", false ), // no exponent (end)
-                       array( "5eee1", false ), // no exponent (multiple e)
-                       array( "5e++", false ), // no exponent (other symbol)
                );
        }
 
@@ -107,7 +101,10 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
                $minified = JavaScriptMinifier::minify( $code );
 
                // JSMin+'s parser will throw an exception if output is not valid JS.
+               // suppression of warnings needed for stupid crap
+               wfSuppressWarnings();
                $parser = new JSParser();
+               wfRestoreWarnings();
                $parser->parse( $minified, 'minify-test.js', 1 );
 
                $this->assertEquals( $expectedOutput, $minified, "Minified output should be in the form expected." );