From f00192e0c7d28fac877975391af3c318c10e4160 Mon Sep 17 00:00:00 2001 From: Simon Ninon Date: Thu, 16 Feb 2017 17:54:26 +0100 Subject: [PATCH] fix issue #50: now handle array with -1 as length and return a null reply instead of raising an invalid format exception --- sources/builders/array_builder.cpp | 7 ++++--- tests/sources/spec/builders/array_builder_spec.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/sources/builders/array_builder.cpp b/sources/builders/array_builder.cpp index e74baa53..7a9eeb4e 100644 --- a/sources/builders/array_builder.cpp +++ b/sources/builders/array_builder.cpp @@ -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; diff --git a/tests/sources/spec/builders/array_builder_spec.cpp b/tests/sources/spec/builders/array_builder_spec.cpp index b613b6c3..a2186a09 100644 --- a/tests/sources/spec/builders/array_builder_spec.cpp +++ b/tests/sources/spec/builders/array_builder_spec.cpp @@ -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()); }