mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +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:
parent
89315787ae
commit
e265d81277
3 changed files with 29 additions and 8 deletions
|
@ -1777,10 +1777,12 @@ bool ECMA262Parser::parse_character_class(ByteCode& stack, size_t& match_length_
|
|||
|
||||
Vector<CompareTypeAndValuePair> compares;
|
||||
|
||||
auto uses_explicit_or_semantics = false;
|
||||
if (match(TokenType::Circumflex)) {
|
||||
// Negated charclass
|
||||
consume();
|
||||
compares.empend(CompareTypeAndValuePair { CharacterCompareType::Inverse, 0 });
|
||||
uses_explicit_or_semantics = true;
|
||||
}
|
||||
|
||||
// ClassContents :: [empty]
|
||||
|
@ -1800,6 +1802,11 @@ bool ECMA262Parser::parse_character_class(ByteCode& stack, size_t& match_length_
|
|||
if (flags.unicode_sets && !parse_class_set_expression(compares))
|
||||
return false;
|
||||
|
||||
if (uses_explicit_or_semantics && compares.size() > 2) {
|
||||
compares.insert(1, CompareTypeAndValuePair { CharacterCompareType::Or, 0 });
|
||||
compares.empend(CompareTypeAndValuePair { CharacterCompareType::EndAndOr, 0 });
|
||||
}
|
||||
|
||||
match_length_minimum += 1;
|
||||
stack.insert_bytecode_compare_values(move(compares));
|
||||
return true;
|
||||
|
@ -2466,9 +2473,9 @@ DeprecatedFlyString ECMA262Parser::read_capture_group_specifier(bool take_starti
|
|||
{
|
||||
static auto id_start_category = Unicode::property_from_string("ID_Start"sv);
|
||||
static auto id_continue_category = Unicode::property_from_string("ID_Continue"sv);
|
||||
static constexpr const u32 REPLACEMENT_CHARACTER = 0xFFFD;
|
||||
constexpr const u32 ZERO_WIDTH_NON_JOINER { 0x200C };
|
||||
constexpr const u32 ZERO_WIDTH_JOINER { 0x200D };
|
||||
static constexpr u32 const REPLACEMENT_CHARACTER = 0xFFFD;
|
||||
constexpr u32 const ZERO_WIDTH_NON_JOINER { 0x200C };
|
||||
constexpr u32 const ZERO_WIDTH_JOINER { 0x200D };
|
||||
|
||||
if (take_starting_angle_bracket && !consume("<"))
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue