1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibRegex: Correct And/Or and inversion interplay semantics

This commit also fixes an incorrect test case from very early on, our
behaviour now matches the ECMA262 spec in this case.

Fixes #21786.
This commit is contained in:
Ali Mohammad Pur 2024-01-11 12:51:13 +03:30 committed by Andreas Kling
parent 89315787ae
commit e265d81277
3 changed files with 29 additions and 8 deletions

View file

@ -648,7 +648,7 @@ TEST_CASE(ECMA262_match)
{ "^[\\0-\\x1f]$"sv, "\n"sv },
{ .pattern = "\\bhello\\B"sv, .subject = "hello1"sv, .options = ECMAScriptFlags::Global },
{ "\\b.*\\b"sv, "hello1"sv },
{ "[^\\D\\S]{2}"sv, "1 "sv },
{ "[^\\D\\S]{2}"sv, "1 "sv, false },
{ "bar(?=f.)foo"sv, "barfoo"sv },
{ "bar(?=foo)bar"sv, "barbar"sv, false },
{ "bar(?!foo)bar"sv, "barbar"sv, true },
@ -1174,6 +1174,14 @@ TEST_CASE(inversion_state_in_char_class)
EXPECT_EQ(result.capture_group_matches.first()[0].view.to_byte_string(), "slideNumbers"sv);
EXPECT_EQ(result.capture_group_matches.first()[1].view.to_byte_string(), "}"sv);
}
{
// #21786, /[^\S\n]/.exec("\n") should be null, not [ "\n" ].
// This was a general confusion between the inversion state and the negation state (temp inverse).
Regex<ECMA262> re("[^\\S\\n]", ECMAScriptFlags::Global | (ECMAScriptFlags)regex::AllFlags::SingleMatch);
auto result = re.match("\n"sv);
EXPECT_EQ(result.success, false);
}
}
TEST_CASE(mismatching_brackets)