diff options
author | Michael Grunder <michael.grunder@gmail.com> | 2023-04-14 10:08:36 -0700 |
---|---|---|
committer | Michael Grunder <michael.grunder@gmail.com> | 2023-04-14 12:41:58 -0700 |
commit | 563b062e37a869dea30b6d95c55c1bbc44bc15dd (patch) | |
tree | 3e132e073511f5db8083a9eb82cc1e24f0c28fdd | |
parent | 04c1b5b0292da1c6515baf6cb5b5b9bb882f38d7 (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.c | 3 | ||||
-rw-r--r-- | test.c | 10 |
2 files changed, 12 insertions, 1 deletions
@@ -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); @@ -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); |