Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common/chat-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ bool common_chat_msg_parser::try_consume_literal(const std::string & literal) {
auto pos = pos_;
for (auto i = 0u; i < literal.size(); ++i) {
if (pos >= input_.size()) {
if (is_partial() && i > 0) {
// For partial message, whose suffix matches the literal, report
// that it can be consumed. We need more content to be able to
// tell otherwise.
pos_ = pos;
return true;
}
return false;
}
if (input_[pos] != literal[i]) {
Expand Down
8 changes: 8 additions & 0 deletions tests/test-chat-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ static void test_regex() {
common_chat_msg_parser builder("Hello,", is_partial, {});
assert_equals(false, builder.try_consume_literal("Oh"));
}
{
common_chat_msg_parser builder("<some>", false, {});
assert_equals(false, builder.try_consume_literal("<some><suffix>"));
}
{
common_chat_msg_parser builder("<some>", true, {});
assert_equals(true, builder.try_consume_literal("<some><suffix>"));
}
}

const std::vector<std::string> barely_healable_jsons = {
Expand Down
Loading