Skip to content

Commit

Permalink
Accept -nan per the RESP3 spec recommendation.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-grunder committed Apr 14, 2023
1 parent 04c1b5b commit 563b062
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 563b062

Please sign in to comment.