Fix type for nil objects

This commit is contained in:
Pieter Noordhuis 2011-07-15 11:42:17 +02:00
parent 4234b1cf2c
commit fdc802349f
2 changed files with 38 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;