Index: trunk/phase3/includes/libs/JavaScriptMinifier.php |
— | — | @@ -489,8 +489,11 @@ |
490 | 490 | ) { |
491 | 491 | // Hex numeric literal |
492 | 492 | $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; |
495 | 498 | } elseif( |
496 | 499 | ctype_digit( $ch ) |
497 | 500 | || ( $ch === '.' && $pos + 1 < $length && ctype_digit( $s[$pos + 1] ) ) |
— | — | @@ -498,19 +501,28 @@ |
499 | 502 | $end += strspn( $s, '0123456789', $end ); |
500 | 503 | $decimal = strspn( $s, '.', $end ); |
501 | 504 | 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; |
506 | 513 | } |
507 | 514 | $exponent = strspn( $s, 'eE', $end ); |
508 | 515 | if( $exponent ) { |
509 | | - $end += $exponent; |
| 516 | + if ( $exponent > 1 ) { |
| 517 | + return self::parseError($s, $end, 'Number with several E' ); |
| 518 | + } |
| 519 | + |
510 | 520 | // + sign is optional; - sign is required. |
511 | 521 | $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; |
515 | 527 | } |
516 | 528 | } elseif( isset( $opChars[$ch] ) ) { |
517 | 529 | // Punctuation character. Search for the longest matching operator. |
— | — | @@ -587,4 +599,9 @@ |
588 | 600 | } |
589 | 601 | return $out; |
590 | 602 | } |
| 603 | + |
| 604 | + static function parseError($fullJavascript, $position, $errorMsg) { |
| 605 | + // TODO: Handle the error: trigger_error, throw exception, return false... |
| 606 | + return false; |
| 607 | + } |
591 | 608 | } |