r103846 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103845‎ | r103846 | r103847 >
Date:22:20, 21 November 2011
Author:brion
Status:ok
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/libs/JavaScriptMinifierTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/libs/JavaScriptMinifierTest.php
@@ -102,4 +102,40 @@
103103
104104 $this->assertEquals( $expectedOutput, $minified, "Minified output should be in the form expected." );
105105 }
 106+
 107+ /**
 108+ * @dataProvider provideBug32548
 109+ */
 110+ function testBug32548Exponent($num) {
 111+ // Long line breaking was being incorrectly done between the base and
 112+ // exponent part of a number, causing a syntax error. The line should
 113+ // instead break at the start of the number.
 114+ $prefix = 'var longVarName' . str_repeat('_', 973) . '=';
 115+ $suffix = ',shortVarName=0;';
 116+
 117+ $input = $prefix . $num . $suffix;
 118+ $expected = $prefix . "\n" . $num . $suffix;
 119+
 120+ $minified = JavaScriptMinifier::minify( $input );
 121+
 122+ $this->assertEquals( $expected, $minified, "Line breaks must not occur in middle of exponent");
 123+ }
 124+
 125+ function provideBug32548() {
 126+ return array(
 127+ array(
 128+ // This one gets interpreted all together by the prior code;
 129+ // no break at the 'E' happens.
 130+ '1.23456789E55',
 131+ ),
 132+ array(
 133+ // This one breaks under the bad code; splits between 'E' and '+'
 134+ '1.23456789E+5',
 135+ ),
 136+ array(
 137+ // This one breaks under the bad code; splits between 'E' and '-'
 138+ '1.23456789E-5',
 139+ ),
 140+ );
 141+ }
106142 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r103865* (bug 32548) fix minification bug when numeric literal with exponent was spl...brion23:16, 21 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r83885(bug 27528) Incorporate Paul Copperman's minifiercatrope11:44, 14 March 2011

Status & tagging log