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:
aplefull 2025-07-23 20:48:34 +02:00 committed by Ali Mohammad Pur
parent 9b8f6b8108
commit c4eef822de
Notes: github-actions[bot] 2025-10-16 14:39:20 +00:00
5 changed files with 197 additions and 9 deletions

View file

@ -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;
}