From 30d2184dbb6d5f9391c1a63b7eced1c6a3967598 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 22 Nov 2015 17:02:44 +0100 Subject: [PATCH] Throw on other protocols provided than the redis protocol --- index.js | 3 +++ test/connection.spec.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/index.js b/index.js index a070e93b0b..b93ddfe5a3 100644 --- a/index.js +++ b/index.js @@ -1270,6 +1270,9 @@ var createClient = function (port_arg, host_arg, options) { if (parsed.auth) { options.auth_pass = parsed.auth.split(':')[1]; } + if (parsed.protocol !== 'redis:') { + throw new Error('Connection string must use the "redis:" protocol'); + } options.host = parsed.hostname; options.port = parsed.port; } else { diff --git a/test/connection.spec.js b/test/connection.spec.js index ee883f60b6..1c70f62021 100644 --- a/test/connection.spec.js +++ b/test/connection.spec.js @@ -307,6 +307,18 @@ describe("connection tests", function () { } }); + it("throws on protocol other than redis in the redis url", function () { + client = { + end: function() {} + }; + try { + redis.createClient(config.HOST[ip] + ':' + config.PORT); + throw new Error('failed'); + } catch (err) { + assert.equal(err.message, 'Connection string must use the "redis:" protocol'); + } + }); + if (ip === 'IPv4') { it('allows connecting with the redis url and the default port', function (done) { client = redis.createClient('redis://foo:porkchopsandwiches@' + config.HOST[ip]);