From 279fdeae2fdd331197d74d6f31a201bba1bdf7cf Mon Sep 17 00:00:00 2001 From: Youngwook Kim Date: Wed, 22 Nov 2017 10:17:22 +0900 Subject: [PATCH] Add supporting username and password for socket connections This fix adds the ability to use username and password even when using a socket. --- index.js | 8 ++++---- test/parse.js | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0042faec..3e04f547 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,10 @@ function parse(str) { } } + var auth = (result.auth || ':').split(':'); + config.user = auth[0]; + config.password = auth.splice(1).join(':'); + config.port = result.port; if(result.protocol == 'socket:') { config.host = decodeURI(result.pathname); @@ -40,10 +44,6 @@ function parse(str) { } config.database = pathname && decodeURI(pathname); - var auth = (result.auth || ':').split(':'); - config.user = auth[0]; - config.password = auth.splice(1).join(':'); - if (config.ssl === 'true' || config.ssl === '1') { config.ssl = true; } diff --git a/test/parse.js b/test/parse.js index 8ff3ee81..42936733 100644 --- a/test/parse.js +++ b/test/parse.js @@ -52,6 +52,14 @@ describe('parse', function(){ subject.client_encoding.should.equal('utf8'); }); + it('initializing with unix domain socket, username and password', function(){ + var subject = parse('socket://brian:pw@/var/run/?db=mydb'); + subject.user.should.equal('brian'); + subject.password.should.equal('pw'); + subject.host.should.equal('/var/run/'); + subject.database.should.equal('mydb'); + }); + it('password contains < and/or > characters', function(){ var sourceConfig = { user:'brian',