From 9d7211b11480b8d7e68b9624bc99b6d310fa2ff3 Mon Sep 17 00:00:00 2001 From: Choongwoo Han Date: Sun, 11 Sep 2022 19:34:52 -0700 Subject: [PATCH] Fix regex literal /[/]/ --- boa_engine/src/syntax/lexer/regex.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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(