Add supporting password with colon

This commit is contained in:
Ivan Sorokin 2014-09-26 15:59:57 +03:00
parent 245abd6daf
commit fbdd033d6c
2 changed files with 15 additions and 1 deletions

View File

@ -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') {

View File

@ -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);