Two decimal points may be valid, as 5..toString() == (5.).toString()
authorPlatonides <platonides@users.mediawiki.org>
Tue, 22 Nov 2011 18:42:21 +0000 (18:42 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Tue, 22 Nov 2011 18:42:21 +0000 (18:42 +0000)
Added some tests

includes/libs/JavaScriptMinifier.php
tests/phpunit/includes/libs/JavaScriptMinifierTest.php

index d34473f..fc815e2 100644 (file)
@@ -501,8 +501,8 @@ class JavaScriptMinifier {
                                $end += strspn( $s, '0123456789', $end );
                                $decimal = strspn( $s, '.', $end );
                                if ($decimal) {
-                                       if ( $decimal > 1 ) {
-                                               return self::parseError($s, $end, 'The number has several decimal points' );
+                                       if ( $decimal > 2 ) {
+                                               return self::parseError($s, $end, 'The number has too many decimal points' );
                                        }
                                        $end += strspn( $s, '0123456789', $end ) + 1;
                                }
index 5952e43..8303e79 100644 (file)
@@ -84,6 +84,13 @@ class JavaScriptMinifierTest extends MediaWikiTestCase {
                        // And also per spec unicode char escape values should work in identifiers,
                        // as long as it's a valid char. In future it might get normalized.
                        array( "var Ka\\u015dSkatolVal = {}", 'var Ka\\u015dSkatolVal={}'),
+
+                       /* Some structures that might look invalid at first sight */
+                       array( "var a = 5.;", "var a=5.;" ),
+                       array( "5.0.toString();", "5.0.toString();" ),
+                       array( "5..toString();", "5..toString();" ),
+                       array( "5...toString();", false ),
+                       array( "5.\n.toString();", '5..toString();' ),
                );
        }