From: Brion Vibber Date: Mon, 21 Nov 2011 22:20:06 +0000 (+0000) Subject: Add PHPUnit tests for the minification failure case in bug 32548. X-Git-Tag: 1.31.0-rc.0~26367 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=8bf802734c4b5f30f9231b7ce2c1c455c6c50e6e;p=lhc%2Fweb%2Fwiklou.git Add PHPUnit tests for the minification failure case in bug 32548. 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. --- diff --git a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php index aa05500e63..c78b41292a 100644 --- a/tests/phpunit/includes/libs/JavaScriptMinifierTest.php +++ b/tests/phpunit/includes/libs/JavaScriptMinifierTest.php @@ -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', + ), + ); + } }