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

Commit c4f4e04

Browse files
committed
fix issue #50: now handle array with -1 as length and return a null reply instead of raising an invalid format exception
2 parents 41a57a6 + f00192e commit c4f4e04

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

sources/builders/array_builder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ array_builder::fetch_array_size(std::string& buffer) {
4545

4646
int64_t size = m_int_builder.get_integer();
4747
if (size < 0) {
48-
__CPP_REDIS_LOG(error, "cpp_redis::builders::array_builder receives invalid array size");
49-
throw redis_error("Invalid array size");
48+
m_reply.set();
49+
m_reply_ready = true;
5050
}
51-
else if (size == 0)
51+
else if (size == 0) {
5252
m_reply_ready = true;
53+
}
5354

5455
m_array_size = size;
5556

tests/sources/spec/builders/array_builder_spec.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,11 @@ TEST(ArrayBuilder, InvalidSize) {
141141
cpp_redis::builders::array_builder builder;
142142

143143
std::string buffer = "-1\r\n";
144-
EXPECT_THROW(builder << buffer, cpp_redis::redis_error);
144+
builder << buffer;
145+
146+
EXPECT_EQ(true, builder.reply_ready());
147+
EXPECT_EQ("", buffer);
148+
149+
auto reply = builder.get_reply();
150+
EXPECT_TRUE(reply.is_null());
145151
}

0 commit comments

Comments
 (0)