From fbdd033d6c90cf5f9c2f6f258bc77a2184345f20 Mon Sep 17 00:00:00 2001 From: Ivan Sorokin Date: Fri, 26 Sep 2014 15:59:57 +0300 Subject: [PATCH] Add supporting password with colon --- index.js | 2 +- test/parse.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index b041a208..ac2fd64c 100644 --- a/index.js +++ b/index.js @@ -47,7 +47,7 @@ function parse(str) { var auth = (result.auth || ':').split(':'); config.user = auth[0]; - config.password = auth[1]; + config.password = auth.splice(1).join(':'); var ssl = result.query.ssl; if (ssl === 'true' || ssl === '1') { diff --git a/test/parse.js b/test/parse.js index 89269429..c1494c31 100644 --- a/test/parse.js +++ b/test/parse.js @@ -69,6 +69,20 @@ test('password contains < and/or > characters', function(t){ t.end(); }); +test('password contains colons', function(t){ + var sourceConfig = { + user:'brian', + password: 'hello:pass:world', + port: 5432, + host: 'localhost', + database: 'postgres' + }; + var connectionString = 'postgres://' + sourceConfig.user + ':' + sourceConfig.password + '@' + sourceConfig.host + ':' + sourceConfig.port + '/' + sourceConfig.database; + var subject = parse(connectionString); + t.equal(subject.password, sourceConfig.password); + t.end(); +}); + test('username or password contains weird characters', function(t){ var strang = 'pg://my f%irst name:is&%awesome!@localhost:9000'; var subject = parse(strang);