r103915 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103914‎ | r103915 | r103916 >
Date:16:21, 22 November 2011
Author:platonides
Status:resolved (Comments)
Tags:
Comment:
Fix r103865 fixmes about case where there a parse error should be raised.
Also detect as an error 1..0 or 1eeeeee5
Modified paths:
  • /trunk/phase3/includes/libs/JavaScriptMinifier.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/libs/JavaScriptMinifier.php
@@ -489,8 +489,11 @@
490490 ) {
491491 // Hex numeric literal
492492 $end++; // x or X
493 - $end += strspn( $s, '0123456789ABCDEFabcdef', $end );
494 - // @fixme if no hex digits, parse error
 493+ $len = strspn( $s, '0123456789ABCDEFabcdef', $end );
 494+ if ( !$len ) {
 495+ return self::parseError($s, $pos, 'Expected a hexadecimal number but found ' . substr( $s, $pos, 5 ) . '...' );
 496+ }
 497+ $end += $len;
495498 } elseif(
496499 ctype_digit( $ch )
497500 || ( $ch === '.' && $pos + 1 < $length && ctype_digit( $s[$pos + 1] ) )
@@ -498,19 +501,28 @@
499502 $end += strspn( $s, '0123456789', $end );
500503 $decimal = strspn( $s, '.', $end );
501504 if ($decimal) {
502 - $end += $decimal;
503 - $end += strspn( $s, '0123456789', $end );
504 - // @fixme If no decimal digits after the . we cannot be followed
505 - // by an identifier, and should throw a parse error
 505+ if ( $decimal > 1 ) {
 506+ return self::parseError($s, $end, 'The number has several decimal points' );
 507+ }
 508+ $len = strspn( $s, '0123456789', $end );
 509+ if ( !$len ) {
 510+ return self::parseError($s, $pos, 'No numbers after decimal point' );
 511+ }
 512+ $end += $len + 1;
506513 }
507514 $exponent = strspn( $s, 'eE', $end );
508515 if( $exponent ) {
509 - $end += $exponent;
 516+ if ( $exponent > 1 ) {
 517+ return self::parseError($s, $end, 'Number with several E' );
 518+ }
 519+
510520 // + sign is optional; - sign is required.
511521 $end += strspn( $s, '-+', $end );
512 - $end += strspn( $s, '0123456789', $end );
513 - // @fixme if no decimal digits after the e/+/- we should
514 - // throw a parse error
 522+ $len = strspn( $s, '0123456789', $end );
 523+ if ( !$len ) {
 524+ return self::parseError($s, $pos, 'No decimal digits after e, how many zeroes should be added?' );
 525+ }
 526+ $end += $len + 1;
515527 }
516528 } elseif( isset( $opChars[$ch] ) ) {
517529 // Punctuation character. Search for the longest matching operator.
@@ -587,4 +599,9 @@
588600 }
589601 return $out;
590602 }
 603+
 604+ static function parseError($fullJavascript, $position, $errorMsg) {
 605+ // TODO: Handle the error: trigger_error, throw exception, return false...
 606+ return false;
 607+ }
591608 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r103928Follow-up r103915. The @fixme of r103865 was wrong....platonides17:48, 22 November 2011
r103931Follow-up r103915: We need to increment $end before the strcspn....platonides18:10, 22 November 2011
r103978Followup r103865 and r103915...brion23:10, 22 November 2011

Past revisions this follows-up on

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

Comments

#Comment by Brion VIBBER (talk | contribs)   18:30, 22 November 2011

needs tests


Seems to incorrectly break numbers with a following decimal and no digits.

#Comment by Brion VIBBER (talk | contribs)   23:13, 22 November 2011

that seems to have been cleaned up in the above

Status & tagging log