diff --git a/common/chat-parser.cpp b/common/chat-parser.cpp index 96ba8f533ef1b..e72efa249df12 100644 --- a/common/chat-parser.cpp +++ b/common/chat-parser.cpp @@ -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]) { diff --git a/tests/test-chat-parser.cpp b/tests/test-chat-parser.cpp index 59e44e07d25ed..4c059e0623363 100644 --- a/tests/test-chat-parser.cpp +++ b/tests/test-chat-parser.cpp @@ -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("", false, {}); + assert_equals(false, builder.try_consume_literal("")); + } + { + common_chat_msg_parser builder("", true, {}); + assert_equals(true, builder.try_consume_literal("")); + } } const std::vector barely_healable_jsons = {