Add PHPUnit tests for the minification failure case in bug 32548.
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 21 Nov 2011 22:20:06 +0000 (22:20 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 21 Nov 2011 22:20:06 +0000 (22:20 +0000)
This will trigger 2 test failures, where an exponent in a JS numeric literal gets split over line breaks at the '-' or '+', causing a parse error in the resulting output.
A number with the same string length but without using + or - in the exponent passes through fine, indicating that it's the -/+ that's getting misinterpreted.

tests/phpunit/includes/libs/JavaScriptMinifierTest.php

index aa05500..c78b412 100644 (file)
@@ -102,4 +102,40 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
 
                $this->assertEquals( $expectedOutput, $minified, "Minified output should be in the form expected." );
        }
+
+       /**
+        * @dataProvider provideBug32548
+        */
+       function testBug32548Exponent($num) {
+               // Long line breaking was being incorrectly done between the base and
+               // exponent part of a number, causing a syntax error. The line should
+               // instead break at the start of the number.
+               $prefix = 'var longVarName' . str_repeat('_', 973) . '=';
+               $suffix = ',shortVarName=0;';
+
+               $input = $prefix . $num . $suffix;
+               $expected = $prefix . "\n" . $num . $suffix;
+
+               $minified = JavaScriptMinifier::minify( $input );
+
+               $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent");
+       }
+
+       function provideBug32548() {
+               return array(
+                       array(
+                               // This one gets interpreted all together by the prior code;
+                               // no break at the 'E' happens.
+                               '1.23456789E55',                                
+                       ),
+                       array(
+                               // This one breaks under the bad code; splits between 'E' and '+'
+                               '1.23456789E+5',
+                       ),
+                       array(
+                               // This one breaks under the bad code; splits between 'E' and '-'
+                               '1.23456789E-5',
+                       ),
+               );
+       }
 }