Merge "Resolve required parameter after optional parameter in Linker"
[lhc/web/wiklou.git] / includes / libs / JavaScriptMinifier.php
index a1a93d2..2e8b591 100644 (file)
@@ -4,7 +4,10 @@
  *
  * @file
  * @author Paul Copperman <paul.copperman@gmail.com>
- * @license Choose any of Apache, MIT, GPL, LGPL
+ * @license Apache-2.0
+ * @license MIT
+ * @license GPL-2.0-or-later
+ * @license LGPL-2.1-or-later
  */
 
 /**
@@ -498,6 +501,13 @@ class JavaScriptMinifier {
                                        } while ( $end - 2 < $length && $s[$end - 2] === '\\' );
                                        // Correction (1): Undo speculative add, keep only one (end of regexp)
                                        $end--;
+                                       if ( $end > $length ) {
+                                               // Correction (2): Loop wrongly assumed "]" was seen
+                                               // String ended without ending char class or regexp. Correct $end.
+                                               // TODO: This is invalid and should throw.
+                                               $end--;
+                                               break;
+                                       }
                                }
                                // Search past the regexp modifiers (gi)
                                while ( $end < $length && ctype_alpha( $s[$end] ) ) {
@@ -565,7 +575,7 @@ class JavaScriptMinifier {
 
                        // Now get the token type from our type array
                        $token = substr( $s, $pos, $end - $pos ); // so $end - $pos == strlen( $token )
-                       $type = isset( $tokenTypes[$token] ) ? $tokenTypes[$token] : self::TYPE_LITERAL;
+                       $type = $tokenTypes[$token] ?? self::TYPE_LITERAL;
 
                        if ( $newlineFound && isset( $semicolon[$state][$type] ) ) {
                                // This token triggers the semicolon insertion mechanism of javascript. While we