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 <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2025-01-15 08:45:22 +02:00 committed by GitHub
parent f6441df57a
commit e89c15bc6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View file

@ -232,8 +232,12 @@ auto RedisParser::ParseInline(Buffer str) -> ResultConsumed {
} }
uint32_t last_consumed = ptr - str.data(); uint32_t last_consumed = ptr - str.data();
if (ptr == end) { // we have not finished parsing. if (ptr == end) { // we have not finished parsing.
is_broken_token_ = ptr[-1] > 32; // we stopped in the middle of the token. 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}; return {INPUT_PENDING, last_consumed};
} }

View file

@ -281,4 +281,11 @@ TEST_F(RedisParserTest, InlineSplit) {
ASSERT_EQ(RedisParser::OK, Parse("ING\n")); 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 } // namespace facade