Skip to content

Commit

Permalink
fix: fix parsing nested arrays (dragonflydb#1189)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Dunstall <[email protected]>
  • Loading branch information
andydunstall authored May 7, 2023
1 parent dc853fe commit 79da3e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/facade/redis_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);

Expand All @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions src/facade/redis_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 79da3e6

Please sign in to comment.