diff --git a/boa_engine/src/syntax/lexer/regex.rs b/boa_engine/src/syntax/lexer/regex.rs index d18f3922143..ddee084f91f 100644 --- a/boa_engine/src/syntax/lexer/regex.rs +++ b/boa_engine/src/syntax/lexer/regex.rs @@ -41,6 +41,7 @@ impl Tokenizer for RegexLiteral { let _timer = Profiler::global().start_event("RegexLiteral", "Lexing"); let mut body = Vec::new(); + let mut is_class_char = false; // Lex RegularExpressionBody. loop { @@ -54,7 +55,15 @@ impl Tokenizer for RegexLiteral { } Some(b) => { match b { - b'/' => break, // RegularExpressionBody finished. + b'/' if !is_class_char => break, // RegularExpressionBody finished. + b'[' => { + is_class_char = true; + body.push(b); + } + b']' if is_class_char => { + is_class_char = false; + body.push(b); + } b'\n' | b'\r' => { // Not allowed in Regex literal. return Err(Error::syntax(