summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Grunder <michael.grunder@gmail.com>2023-04-14 10:08:36 -0700
committerMichael Grunder <michael.grunder@gmail.com>2023-04-14 12:41:58 -0700
commit563b062e37a869dea30b6d95c55c1bbc44bc15dd (patch)
tree3e132e073511f5db8083a9eb82cc1e24f0c28fdd
parent04c1b5b0292da1c6515baf6cb5b5b9bb882f38d7 (diff)
Accept -nan per the RESP3 spec recommendation.
For reference: https://github.com/redis/redis-specifications/blob/master/protocol/RESP3.md
-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);