Skip to content

Commit

Permalink
terminal: strict state check when injecting lf
Browse files Browse the repository at this point in the history
avoid accidentally returning Lf as remaining string when the given line is already terminated
  • Loading branch information
mcspr committed Jan 29, 2025
1 parent 356fcc6 commit 776acaa
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions code/espurna/terminal_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,26 @@ Result Parser::operator()(StringView line, bool inject_newline) {
}

out:
if (inject_newline && it == line.end()) {
inject_newline = false;
it = Lf.begin();
end = Lf.end();
goto loop;
switch (state) {
case State::CarriageReturn:
case State::CarriageReturnAfterText:
case State::Text:
case State::Initial:
case State::SkipUntilNewLine:
case State::AfterQuote:
if (inject_newline) {
inject_newline = false;
it = Lf.begin();
end = Lf.end();
goto loop;
}
break;

default:
break;
}

if (it != end) {
if ((it >= line.begin()) && (it <= line.end())) {
result = StringView(it, end);
}

Expand Down

0 comments on commit 776acaa

Please sign in to comment.