From e89c15bc6a2f0d9e02a1a5bb5806175578d46481 Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Wed, 15 Jan 2025 08:45:22 +0200 Subject: [PATCH] fix: resp inline parsing correctly resets itself (#4458) With empty inline string, the parser failed to continue parsing correctly the non-inline input. Signed-off-by: Roman Gershman --- src/facade/redis_parser.cc | 8 ++++++-- src/facade/redis_parser_test.cc | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/facade/redis_parser.cc b/src/facade/redis_parser.cc index 5f94c1b4a..40f439b44 100644 --- a/src/facade/redis_parser.cc +++ b/src/facade/redis_parser.cc @@ -232,8 +232,12 @@ auto RedisParser::ParseInline(Buffer str) -> ResultConsumed { } uint32_t last_consumed = ptr - str.data(); - if (ptr == end) { // we have not finished parsing. - is_broken_token_ = ptr[-1] > 32; // we stopped in the middle of the token. + if (ptr == end) { // we have not finished parsing. + if (cached_expr_->empty()) { + state_ = CMD_COMPLETE_S; // have not found anything besides whitespace. + } else { + is_broken_token_ = ptr[-1] > 32; // we stopped in the middle of the token. + } return {INPUT_PENDING, last_consumed}; } diff --git a/src/facade/redis_parser_test.cc b/src/facade/redis_parser_test.cc index dc59e5783..339850c6d 100644 --- a/src/facade/redis_parser_test.cc +++ b/src/facade/redis_parser_test.cc @@ -281,4 +281,11 @@ TEST_F(RedisParserTest, InlineSplit) { ASSERT_EQ(RedisParser::OK, Parse("ING\n")); } +TEST_F(RedisParserTest, InlineReset) { + ASSERT_EQ(RedisParser::INPUT_PENDING, Parse("\t \r\n")); + EXPECT_EQ(4, consumed_); + ASSERT_EQ(RedisParser::OK, Parse("*1\r\n$3\r\nfoo\r\n")); + EXPECT_EQ(13, consumed_); +} + } // namespace facade