From 37de322d73d78b6a05bce6657cd547d5ea247457 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 22 Dec 2017 19:00:42 +0100 Subject: [PATCH] JavaScriptMinifier: Improve docs around parsing of regexp literals Bug: T75556 Change-Id: Ifcb6bc21418dfc2e1d3e44dbd2497a0f5f691bf3 --- includes/libs/JavaScriptMinifier.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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--; }; -- 2.20.1