Skip to content

Commit e418293

Browse files
committed
fix(regex): reject empty unicode brace escape
1 parent cb67bcb commit e418293

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

string/internal/regex_parser/parser.mbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fn Parser::class_atom(
6363
}
6464
(rest, Char(c))
6565
}
66+
(re"^\\u", after=_) => raise ctx.error_at(rest, HINT_INVALID_ESCAPE)
6667
(re"^\\" + (re"[\^$\\.*+?()\[\]{}|/\"\-:&]" as c), after=rest) =>
6768
(rest, Char(c.to_int()))
6869
(re"^\[:ascii:\]", after=rest) => (rest, Class(posix_cset_ascii))
@@ -289,6 +290,7 @@ fn Parser::term(
289290
}
290291
(rest, @re.char(@re.RecharSet::char(c)), false)
291292
}
293+
(re"^\\u", after=_) => raise ctx.error_at(rest, HINT_INVALID_ESCAPE)
292294
(re"^\\" + (re"[\^$\\.*+?()\[\]{}|/\"]" as c), after=rest) =>
293295
(rest, @re.char(@re.RecharSet::char(c.to_int())), false)
294296
(re"^\\.", after=_) => raise ctx.error_at(rest, HINT_INVALID_ESCAPE)

string/internal/regex_parser/parser_test.mbt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,18 @@ test "parse/error_invalid_escape" {
894894
)
895895
}
896896

897+
///|
898+
test "parse/error_empty_unicode_brace_escape" {
899+
debug_inspect(
900+
Ok(parse(profile=profile_unicode(), mode=String, "[\\u{}]")) catch {
901+
e => Err(e)
902+
},
903+
content=(
904+
#|Err(ParserError(at=1, hint="Invalid escape sequence"))
905+
),
906+
)
907+
}
908+
897909
///|
898910
test "parse/error_unicode_out_of_range" {
899911
debug_inspect(

0 commit comments

Comments
 (0)