From 97db227a8d2098f82472b08e107e02532e73616d Mon Sep 17 00:00:00 2001 From: pbihler Date: Mon, 8 Dec 2014 13:02:09 +0100 Subject: [PATCH] Fix for channel names with spaces. Fixes #691 Channel names with spaces were not properly resubscribed after a reconnection. Conflicts: index.js --- index.js | 3 ++- test/pubsub.spec.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 2661c19292..45b20823ab 100644 --- a/index.js +++ b/index.js @@ -308,7 +308,8 @@ RedisClient.prototype.on_ready = function () { } }; Object.keys(this.subscription_set).forEach(function (key) { - var parts = key.split(" "); + var space_index = key.indexOf(" "); + var parts = [key.slice(0, space_index), key.slice(space_index + 1)]; debug("Sending pub/sub on_ready " + parts[0] + ", " + parts[1]); callback_count++; self.send_command(parts[0] + "scribe", [parts[1]], callback); diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index 09cdac4f7f..4cf801758d 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -43,14 +43,22 @@ describe("publish/subscribe", function () { }); describe('subscribe', function () { - it('fires a subscribe event for each channel subscribed to', function (done) { + it('fires a subscribe event for each channel subscribed to even after reconnecting', function (done) { + var a = false; sub.on("subscribe", function (chnl, count) { if (chnl === channel2) { assert.equal(2, count); - return done(); + if (a) { + return done(); + } + sub.stream.destroy(); } }); + sub.on('reconnecting', function() { + a = true; + }); + sub.subscribe(channel, channel2); });