mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
LibRegex+LibJS: Avoid searching for more than one match in JS RegExps
All of JS's regular expression APIs only want a single match, so avoid trying to produce more (which will be discarded anyway).
This commit is contained in:
parent
4c506f91fe
commit
2b028f6faa
5 changed files with 28 additions and 5 deletions
|
@ -990,3 +990,15 @@ TEST_CASE(negative_lookahead)
|
|||
EXPECT_EQ(re.match(":foobar").success, true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(single_match_flag)
|
||||
{
|
||||
{
|
||||
// Ensure that only a single match is produced and nothing past that.
|
||||
Regex<ECMA262> re("[\\u0008-\\uffff]"sv, ECMAScriptFlags::Global | (ECMAScriptFlags)regex::AllFlags::SingleMatch);
|
||||
auto result = re.match("ABC");
|
||||
EXPECT_EQ(result.success, true);
|
||||
EXPECT_EQ(result.matches.size(), 1u);
|
||||
EXPECT_EQ(result.matches.first().view.to_string(), "A"sv);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue