mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibRegex: Treat backwards jumps to IP 0 as normal backwards jumps too
This shows up in something like /\d+|x/, where the `+` ends up jumping to the start of its own alternative.
This commit is contained in:
parent
045880e6c7
commit
4d27257c45
2 changed files with 3 additions and 1 deletions
|
@ -1051,6 +1051,8 @@ TEST_CASE(optimizer_alternation)
|
||||||
Tuple { "ab|ac|ad|bc"sv, "bc"sv, 2u },
|
Tuple { "ab|ac|ad|bc"sv, "bc"sv, 2u },
|
||||||
// Should not crash on backwards jumps introduced by '.*'.
|
// Should not crash on backwards jumps introduced by '.*'.
|
||||||
Tuple { "\\bDroid\\b.*Build|XT912|XT928|XT926|XT915|XT919|XT925|XT1021|\\bMoto E\\b|XT1068|XT1092|XT1052"sv, "XT1068"sv, 6u },
|
Tuple { "\\bDroid\\b.*Build|XT912|XT928|XT926|XT915|XT919|XT925|XT1021|\\bMoto E\\b|XT1068|XT1092|XT1052"sv, "XT1068"sv, 6u },
|
||||||
|
// Backwards jumps to IP 0 are normal jumps too.
|
||||||
|
Tuple { "^(\\d+|x)"sv, "42"sv, 2u },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto& test : tests) {
|
for (auto& test : tests) {
|
||||||
|
|
|
@ -1150,7 +1150,7 @@ void Optimizer::append_alternation(ByteCode& target, Span<ByteCode> alternatives
|
||||||
VERIFY(node->has_metadata());
|
VERIFY(node->has_metadata());
|
||||||
QualifiedIP ip = node->metadata_value().first();
|
QualifiedIP ip = node->metadata_value().first();
|
||||||
auto intended_jump_ip = ip.instruction_position + jump_offset + opcode.size();
|
auto intended_jump_ip = ip.instruction_position + jump_offset + opcode.size();
|
||||||
if (jump_offset < 0 && intended_jump_ip > 0) {
|
if (jump_offset < 0) {
|
||||||
VERIFY(has_any_backwards_jump);
|
VERIFY(has_any_backwards_jump);
|
||||||
// We should've already seen this instruction, so we can just patch it in.
|
// We should've already seen this instruction, so we can just patch it in.
|
||||||
auto& ip_mapping = ip_mapping_for_alternative(ip.alternative_index);
|
auto& ip_mapping = ip_mapping_for_alternative(ip.alternative_index);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue