1
Fork 0
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:
Ali Mohammad Pur 2021-08-31 22:27:08 +04:30 committed by Andreas Kling
parent fcdd7aa990
commit dd82c2e9b4
3 changed files with 59 additions and 24 deletions

View file

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