summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--read.c3
-rw-r--r--test.c10
2 files changed, 12 insertions, 1 deletions
diff --git a/read.c b/read.c
index 8e6d21b..9c8f869 100644
--- a/read.c
+++ b/read.c
@@ -303,7 +303,8 @@ static int processLineItem(redisReader *r) {
d = INFINITY; /* Positive infinite. */
} else if (len == 4 && strcasecmp(buf,"-inf") == 0) {
d = -INFINITY; /* Negative infinite. */
- } else if (len == 3 && strcasecmp(buf,"nan") == 0) {
+ } else if ((len == 3 && strcasecmp(buf,"nan") == 0) ||
+ (len == 4 && strcasecmp(buf, "-nan") == 0)) {
d = NAN; /* nan. */
} else {
d = strtod((char*)buf,&eptr);
diff --git a/test.c b/test.c
index c1065ff..77e7f1a 100644
--- a/test.c
+++ b/test.c
@@ -684,6 +684,16 @@ static void test_reply_reader(void) {
freeReplyObject(reply);
redisReaderFree(reader);
+ test("Correctly parses RESP3 double -Nan: ");
+ reader = redisReaderCreate();
+ redisReaderFeed(reader, ",-nan\r\n", 7);
+ ret = redisReaderGetReply(reader, &reply);
+ test_cond(ret == REDIS_OK &&
+ ((redisReply*)reply)->type == REDIS_REPLY_DOUBLE &&
+ isnan(((redisReply*)reply)->dval));
+ freeReplyObject(reply);
+ redisReaderFree(reader);
+
test("Can parse RESP3 nil: ");
reader = redisReaderCreate();
redisReaderFeed(reader, "_\r\n",3);