Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Commit

Permalink
fix issue #50: now handle array with -1 as length and return a null r…
Browse files Browse the repository at this point in the history
…eply instead of raising an invalid format exception
  • Loading branch information
Cylix committed Feb 16, 2017
2 parents 41a57a6 + f00192e commit c4f4e04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions sources/builders/array_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ array_builder::fetch_array_size(std::string& buffer) {

int64_t size = m_int_builder.get_integer();
if (size < 0) {
__CPP_REDIS_LOG(error, "cpp_redis::builders::array_builder receives invalid array size");
throw redis_error("Invalid array size");
m_reply.set();
m_reply_ready = true;
}
else if (size == 0)
else if (size == 0) {
m_reply_ready = true;
}

m_array_size = size;

Expand Down
8 changes: 7 additions & 1 deletion tests/sources/spec/builders/array_builder_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,11 @@ TEST(ArrayBuilder, InvalidSize) {
cpp_redis::builders::array_builder builder;

std::string buffer = "-1\r\n";
EXPECT_THROW(builder << buffer, cpp_redis::redis_error);
builder << buffer;

EXPECT_EQ(true, builder.reply_ready());
EXPECT_EQ("", buffer);

auto reply = builder.get_reply();
EXPECT_TRUE(reply.is_null());
}

0 comments on commit c4f4e04

Please sign in to comment.