1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

fix: fix parsing nested arrays (#1189)

Signed-off-by: Andrew Dunstall <andydunstall@hotmail.co.uk>
This commit is contained in:
Andy Dunstall 2023-05-07 11:34:36 +01:00 committed by GitHub
parent dc853fe4bd
commit 79da3e6637
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -276,9 +276,6 @@ auto RedisParser::ConsumeArrayLen(Buffer str) -> Result {
return OK;
}
DVLOG(1) << "PushStack: (" << len << ", " << cached_expr_ << ")";
parse_stack_.emplace_back(len, cached_expr_);
if (state_ == PARSE_ARG_S) {
DCHECK(!server_mode_);
@ -292,6 +289,9 @@ auto RedisParser::ConsumeArrayLen(Buffer str) -> Result {
state_ = PARSE_ARG_S;
}
DVLOG(1) << "PushStack: (" << len << ", " << cached_expr_ << ")";
parse_stack_.emplace_back(len, cached_expr_);
return OK;
}

View file

@ -197,4 +197,16 @@ TEST_F(RedisParserTest, NILs) {
ASSERT_EQ(RedisParser::OK, Parse("_\r\n"));
}
TEST_F(RedisParserTest, NestedArray) {
parser_.SetClientMode();
// [[['foo'],['bar']],['car']]
ASSERT_EQ(RedisParser::OK,
Parse("*2\r\n*2\r\n*1\r\n$3\r\nfoo\r\n*1\r\n$3\r\nbar\r\n*1\r\n$3\r\ncar\r\n"));
ASSERT_THAT(args_, ElementsAre(ArrArg(2), ArrArg(1)));
ASSERT_THAT(args_[0].GetVec(), ElementsAre(ArrArg(1), ArrArg(1)));
ASSERT_THAT(args_[1].GetVec(), ElementsAre("car"));
}
} // namespace facade