Skip to content

Commit fbdd033

Browse files
author
Ivan Sorokin
committed
Add supporting password with colon
1 parent 245abd6 commit fbdd033

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function parse(str) {
4747

4848
var auth = (result.auth || ':').split(':');
4949
config.user = auth[0];
50-
config.password = auth[1];
50+
config.password = auth.splice(1).join(':');
5151

5252
var ssl = result.query.ssl;
5353
if (ssl === 'true' || ssl === '1') {

test/parse.js

+14
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ test('password contains < and/or > characters', function(t){
6969
t.end();
7070
});
7171

72+
test('password contains colons', function(t){
73+
var sourceConfig = {
74+
user:'brian',
75+
password: 'hello:pass:world',
76+
port: 5432,
77+
host: 'localhost',
78+
database: 'postgres'
79+
};
80+
var connectionString = 'postgres://' + sourceConfig.user + ':' + sourceConfig.password + '@' + sourceConfig.host + ':' + sourceConfig.port + '/' + sourceConfig.database;
81+
var subject = parse(connectionString);
82+
t.equal(subject.password, sourceConfig.password);
83+
t.end();
84+
});
85+
7286
test('username or password contains weird characters', function(t){
7387
var strang = 'pg://my f%irst name:is&%awesome!@localhost:9000';
7488
var subject = parse(strang);

0 commit comments

Comments
 (0)