Commit fdc80234 authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Fix type for nil objects

parent 4234b1cf
......@@ -330,6 +330,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
if (cur->type == REDIS_STRING_T) {
if (i64.i64 < 0) { /* nil bulk */
cur->type = REDIS_NIL_T;
CALLBACK(nil, cur);
goto done;
}
......@@ -346,6 +347,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
if (cur->type == REDIS_ARRAY_T) {
if (i64.i64 < 0) { /* nil multi bulk */
cur->type = REDIS_NIL_T;
CALLBACK(nil, cur);
goto done;
}
......
......@@ -242,6 +242,25 @@ void test_empty_string(redis_parser_t *p) {
test_char_by_char(res, buf, len);
}
void test_nil_string(redis_parser_t *p) {
const char *buf = "$-1\r\n";
size_t len = 5;
redis_protocol_t *res;
/* Parse and check resulting protocol_t */
RESET_PARSER_T(p);
assert_equal_size_t(redis_parser_execute(p, &res, buf, len), len);
assert(res != NULL);
assert_equal_size_t(res->type, REDIS_NIL_T);
assert_equal_size_t(res->poff, 0);
assert_equal_size_t(res->plen, 5);
assert_equal_size_t(res->coff, 0);
assert_equal_size_t(res->clen, 0);
/* Chunked check */
test_char_by_char(res, buf, len);
}
void test_array(redis_parser_t *p) {
const char *buf =
"*2\r\n"
......@@ -304,6 +323,23 @@ void test_empty_array(redis_parser_t *p) {
test_char_by_char(res, buf, len);
}
void test_nil_array(redis_parser_t *p) {
const char *buf = "*-1\r\n";
size_t len = 5;
redis_protocol_t *res;
/* Parse and check resulting protocol_t */
RESET_PARSER_T(p);
assert_equal_size_t(redis_parser_execute(p, &res, buf, len), len);
assert(res != NULL);
assert_equal_size_t(res->type, REDIS_NIL_T);
assert_equal_size_t(res->poff, 0);
assert_equal_size_t(res->plen, 5);
/* Chunked check */
test_char_by_char(res, buf, len);
}
void test_integer(redis_parser_t *p) {
const char *buf = ":1234\r\n";
size_t len = 7;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment