Skip to content

Commit

Permalink
fix(regular_expression): Handle unterminated character class (#5523)
Browse files Browse the repository at this point in the history
`/[/` is reported by `debug_assert!`, but should not.
  • Loading branch information
leaysgur committed Sep 6, 2024
1 parent 10e8984 commit 88b7ddb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/oxc_regular_expression/src/body_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ mod test {
("(?=a){1}", ParserOptions::default().with_unicode_mode()),
("(?!a){1}", ParserOptions::default().with_unicode_mode()),
(r"[\d-\D]", ParserOptions::default().with_unicode_mode()),
("[", ParserOptions::default()),
("[", ParserOptions::default().with_unicode_sets_mode()),
("[[", ParserOptions::default().with_unicode_sets_mode()),
("[[]", ParserOptions::default().with_unicode_sets_mode()),
("[z-a]", ParserOptions::default()),
(r"[a-c]]", ParserOptions::default().with_unicode_mode()),
(
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_regular_expression/src/body_parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,10 @@ impl<'a> PatternParser<'a> {
&mut self,
) -> Result<(ast::CharacterClassContentsKind, Vec<'a, ast::CharacterClassContents<'a>>)> {
// [empty]
if self.reader.peek().filter(|&cp| cp == ']' as u32).is_some() {
if self.reader.peek().filter(|&cp| cp == ']' as u32).is_some()
// Unterminated
|| self.reader.peek().is_none()
{
return Ok((ast::CharacterClassContentsKind::Union, Vec::new_in(self.allocator)));
}

Expand Down

0 comments on commit 88b7ddb

Please sign in to comment.