Permalink
Browse files

Support deeper nesting of multi bulk replies

  • Loading branch information...
pietern committed Aug 28, 2012
1 parent 69687d0 commit 14c4636ded4105d5ee7e730207d63250587e6c71
Showing with 35 additions and 2 deletions.
  1. +1 −1 reader.cc
  2. +1 −1 reader.h
  3. +33 −0 test/reader.js
View
@@ -13,7 +13,7 @@ static void *tryParentize(const redisReadTask *task, const Local<Value> &v) {
if (task->parent != NULL) {
pidx = (size_t)task->parent->obj;
- assert(pidx > 0 && pidx < 3);
+ assert(pidx > 0 && pidx < 9);
/* When there is a parent, it should be an array. */
assert(r->handle[pidx]->IsArray());
View
@@ -28,7 +28,7 @@ class Reader : ObjectWrap {
* from incomplete replies. These are persistent handles because
* Reader::Get might not return a full reply and the objects need to be
* kept around for subsequent calls. */
- Persistent<Value> handle[3];
+ Persistent<Value> handle[9];
/* Helper function to create string/buffer objects. */
Local<Value> createString(char *str, size_t len);
View
@@ -119,6 +119,39 @@ test("NestedMultiBulkReply", function() {
assert.deepEqual([["foo", "bar"], "qux"], reader.get());
});
+test("DeeplyNestedMultiBulkReply", function() {
+ var i;
+ var reader = new hiredis.Reader();
+ var expected = 1;
+
+ for (i = 0; i < 8; i++) {
+ reader.feed("*1\r\n");
+ expected = [expected];
+ }
+
+ reader.feed(":1\r\n");
+
+ assert.deepEqual(reader.get(), expected);
+});
+
+test("TooDeeplyNestedMultiBulkReply", function() {
+ var i;
+ var reader = new hiredis.Reader();
+
+ for (i = 0; i < 9; i++) {
+ reader.feed("*1\r\n");
+ }
+
+ reader.feed(":1\r\n");
+
+ assert.throws(
+ function() {
+ reader.get();
+ },
+ /nested multi/
+ );
+});
+
test("MultiBulkReplyWithNonStringValues", function() {
var reader = new hiredis.Reader();
reader.feed("*3\r\n:1\r\n+OK\r\n$-1\r\n");

0 comments on commit 14c4636

Please sign in to comment.