From: Timo Tijhof Date: Fri, 22 Dec 2017 18:00:42 +0000 (+0100) Subject: JavaScriptMinifier: Improve docs around parsing of regexp literals X-Git-Tag: 1.31.0-rc.0~1113^2 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=37de322d73d78b6a05bce6657cd547d5ea247457;p=lhc%2Fweb%2Fwiklou.git JavaScriptMinifier: Improve docs around parsing of regexp literals Bug: T75556 Change-Id: Ifcb6bc21418dfc2e1d3e44dbd2497a0f5f691bf3 --- diff --git a/includes/libs/JavaScriptMinifier.php b/includes/libs/JavaScriptMinifier.php index 3be9ca160b..bbba33a7ea 100644 --- a/includes/libs/JavaScriptMinifier.php +++ b/includes/libs/JavaScriptMinifier.php @@ -449,18 +449,24 @@ class JavaScriptMinifier { // We have to distinguish between regexp literals and division operators // A division operator is only possible in certain states } elseif( $ch === '/' && !isset( $divStates[$state] ) ) { - // Regexp literal, search to the end, skipping over backslash escapes and - // character classes + // Regexp literal for( ; ; ) { do{ + // Skip until we find "/" (end of regexp), "\" (backslash escapes), + // or "[" (start of character classes). $end += strcspn( $s, '/[\\', $end ) + 2; + // If backslash escape, keep searching... } while( $end - 2 < $length && $s[$end - 2] === '\\' ); $end--; + // If the end, stop here. if( $end - 1 >= $length || $s[$end - 1] === '/' ) { break; } + // (Implicit else), we must've found the start of a char class, + // skip until we find "]" (end of char class), or "\" (backslash escape) do{ $end += strcspn( $s, ']\\', $end ) + 2; + // If backslash escape, keep searching... } while( $end - 2 < $length && $s[$end - 2] === '\\' ); $end--; };