mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
LibRegex: Correctly handle failing in the middle of explicit repeats
- Make sure that all the Repeat ops are reset (otherwise the operation would not be correct when going over the Repeat op a second time) - Make sure that all matches that are allowed to fail are backed by a fork, otherwise the last failing fork would not have anywhere to return to. Fixes #9707.
This commit is contained in:
parent
fcdd7aa990
commit
dd82c2e9b4
3 changed files with 59 additions and 24 deletions
|
@ -189,6 +189,9 @@ void ByteCode::ensure_opcodes_initialized()
|
|||
case OpCodeId::Repeat:
|
||||
s_opcodes[i] = make<OpCode_Repeat>();
|
||||
break;
|
||||
case OpCodeId::ResetRepeat:
|
||||
s_opcodes[i] = make<OpCode_ResetRepeat>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
s_opcodes_initialized = true;
|
||||
|
@ -883,4 +886,13 @@ ALWAYS_INLINE ExecutionResult OpCode_Repeat::execute(MatchInput const&, MatchSta
|
|||
return ExecutionResult::Continue;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ExecutionResult OpCode_ResetRepeat::execute(MatchInput const&, MatchState& state) const
|
||||
{
|
||||
if (id() >= state.repetition_marks.size())
|
||||
state.repetition_marks.resize(id() + 1);
|
||||
|
||||
state.repetition_marks.at(id()) = 0;
|
||||
return ExecutionResult::Continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue