mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-19 15:43:20 +00:00
LibRegex: Fix backreferences to undefined capture groups
Fixes handling of backreferences when the referenced capture group is undefined or hasn't participated in the match. CharacterCompareType::NamedReference is added to distinguish numbered (\1) from named (\k<name>) backreferences. Numbered backreferences use exact group lookup. Named backreferences search for participating groups among duplicates.
This commit is contained in:
parent
9b8f6b8108
commit
c4eef822de
Notes:
github-actions[bot]
2025-10-16 14:39:20 +00:00
Author: https://github.com/aplefull
Commit: c4eef822de
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5590
Reviewed-by: https://github.com/alimpfard ✅
Reviewed-by: https://github.com/gmta
5 changed files with 197 additions and 9 deletions
|
@ -496,7 +496,6 @@ bool PosixBasicParser::parse_nonduplicating_re(ByteCode& bytecode, size_t& match
|
|||
if (try_skip({ backref_name, 2 })) {
|
||||
if (!m_capture_group_seen[i - 1])
|
||||
return set_error(Error::InvalidNumber);
|
||||
match_length_minimum += m_capture_group_minimum_lengths[i - 1];
|
||||
bytecode.insert_bytecode_compare_values({ { CharacterCompareType::Reference, (ByteCodeValueType)i } });
|
||||
return true;
|
||||
}
|
||||
|
@ -1656,8 +1655,7 @@ bool ECMA262Parser::parse_atom_escape(ByteCode& stack, size_t& match_length_mini
|
|||
return false;
|
||||
}
|
||||
|
||||
match_length_minimum += maybe_length.value();
|
||||
stack.insert_bytecode_compare_values({ { CharacterCompareType::Reference, (ByteCodeValueType)group_index } });
|
||||
stack.insert_bytecode_compare_values({ { CharacterCompareType::NamedReference, (ByteCodeValueType)group_index } });
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue