mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
LibRegex: Prevent patterns from matching the empty string twice
Previously, if a pattern matched the empty string (e.g. ".*"), it would match the string twice instead of once. Among other issues, this caused a Regex replacement to duplicate its expected output, since it would replace "both" empty matches.
This commit is contained in:
parent
5bf2cce839
commit
87a961534f
2 changed files with 17 additions and 0 deletions
|
@ -1089,6 +1089,18 @@ TEST_CASE(single_match_flag)
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE(empty_string_wildcard_match)
|
||||
{
|
||||
{
|
||||
// Ensure that the wildcard ".*" matches the empty string exactly once
|
||||
Regex<ECMA262> re(".*"sv, ECMAScriptFlags::Global);
|
||||
auto result = re.match(""sv);
|
||||
EXPECT_EQ(result.success, true);
|
||||
EXPECT_EQ(result.matches.size(), 1u);
|
||||
EXPECT_EQ(result.matches.first().view.to_deprecated_string(), ""sv);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(inversion_state_in_char_class)
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue