From 43c7d7748af8b0ed9e8a1df6203a329084d8b320 Mon Sep 17 00:00:00 2001 From: Choongwoo Han Date: Tue, 13 Sep 2022 04:21:26 +0000 Subject: [PATCH] Fix regex literal /[/]/ (#2277) This PR fixes a case where a forward slash is located in a regex class: `let regex = /[/]/;`. In this case, the forward slash should not close the regex literal. This fixes `test/built-ins/RegExp/regexp-class-chars.js` --- 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 d18f392214..ddee084f91 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(