Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

now we allow single-line replies being used in multi-bulk replies.

  • Loading branch information...
commit 256c3f0a6dd4166f0634faf760f68e8e47ab8d19 1 parent 0d17372
@agentzh agentzh authored
Showing with 53 additions and 14 deletions.
  1. +25 −14 redis-parser.c
  2. +28 −0 t/sanity.t
View
39 redis-parser.c
@@ -432,24 +432,35 @@ parse_multi_bulk_reply(lua_State *L, char **src, const char *last)
for (i = 1; i <= count; i++) {
CHECK_EOF
- if (*p++ != '$') {
- goto invalid;
- }
+ switch (*p) {
+ case '+':
+ case '-':
+ case ':':
+ p++;
+ dst = parse_single_line_reply(p, last, &dst_len);
+ break;
- dst = parse_bulk_reply(p, last, &dst_len);
+ case '$':
+ p++;
+ dst = parse_bulk_reply(p, last, &dst_len);
+ if (dst_len == -2) {
+ dd("bulk %d reply parse fail for multi bulks", i);
+ return PARSE_ERROR;
+ }
- if (dst_len == -2) {
- dd("bulk %d reply parse fail for multi bulks", i);
- return PARSE_ERROR;
- }
+ if (dst_len == -1) {
+ lua_pushnil(L);
+ p = dst + sizeof("\r\n") - 1;
- if (dst_len == -1) {
- lua_pushnil(L);
- p = dst + sizeof("\r\n") - 1;
+ } else {
+ lua_pushlstring(L, dst, dst_len);
+ p = dst + dst_len + sizeof("\r\n") - 1;
+ }
+
+ break;
- } else {
- lua_pushlstring(L, dst, dst_len);
- p = dst + dst_len + sizeof("\r\n") - 1;
+ default:
+ goto invalid;
}
lua_rawseti(L, -2, i);
View
28 t/sanity.t
@@ -416,3 +416,31 @@ print("query == " .. yajl.to_string(query))
--- out
query == "*3\r\n$3\r\nset\r\n$3\r\nfoo\r\n$9\r\n3.1415926\r\n"
+
+
+=== TEST 32: multi bulk reply contains single line reply
+--- lua
+yajl = require('yajl')
+parser = require("redis.parser")
+reply = '*5\r\n$1\r\na\r\n:1\r\n-Bad argument\r\n+32\r\n$3\r\nfoo\r\n'
+res, typ = parser.parse_reply(reply)
+print("typ == " .. typ .. ' == ' .. parser.MULTI_BULK_REPLY)
+print("res == " .. yajl.to_string(res))
+--- out eval
+qq{typ == 5 == 5
+res == ["a","1","Bad argument","32","foo"]\n}
+
+
+
+=== TEST 33: we allow left-over bytes
+--- lua
+yajl = require('yajl')
+parser = require("redis.parser")
+reply = '*3\r\n$1\r\na\r\n:1\r\n-Bad argument\r\n+32\r\n$3\r\nfoo\r\n'
+res, typ = parser.parse_reply(reply)
+print("typ == " .. typ .. ' == ' .. parser.MULTI_BULK_REPLY)
+print("res == " .. yajl.to_string(res))
+--- out eval
+qq{typ == 5 == 5
+res == ["a","1","Bad argument"]\n}
+
Please sign in to comment.
Something went wrong with that request. Please try again.