diff --git a/Tests/LibRegex/Regex.cpp b/Tests/LibRegex/Regex.cpp index f40c48ab55..d88f9cd6a3 100644 --- a/Tests/LibRegex/Regex.cpp +++ b/Tests/LibRegex/Regex.cpp @@ -779,6 +779,23 @@ TEST_CASE(ECMA262_unicode_match) } } +TEST_CASE(ECMA262_unicode_sets_parser_error) +{ + struct _test { + StringView pattern; + regex::Error error; + }; + + constexpr _test tests[] { + { "[[]"sv, regex::Error::InvalidPattern }, + }; + + for (auto test : tests) { + Regex re(test.pattern, (ECMAScriptFlags)regex::AllFlags::UnicodeSets); + EXPECT_EQ(re.parser_result.error, test.error); + } +} + TEST_CASE(ECMA262_unicode_sets_match) { struct _test { diff --git a/Userland/Libraries/LibRegex/RegexParser.cpp b/Userland/Libraries/LibRegex/RegexParser.cpp index 7dd1530d96..475e542e5f 100644 --- a/Userland/Libraries/LibRegex/RegexParser.cpp +++ b/Userland/Libraries/LibRegex/RegexParser.cpp @@ -2224,6 +2224,11 @@ Optional ECMA262Parser::parse_class_set_character() "&&"sv, "!!"sv, "##"sv, "$$"sv, "%%"sv, "**"sv, "++"sv, ",,"sv, ".."sv, "::"sv, ";;"sv, "<<"sv, "=="sv, ">>"sv, "??"sv, "@@"sv, "^^"sv, "``"sv, "~~"sv }; + if (done()) { + set_error(Error::InvalidPattern); + return {}; + } + auto start_position = tell(); ArmedScopeGuard restore { [&] { back(tell() - start_position + 1); } };