replace space by %20 in connection string before passing to url.parse

This commit is contained in:
Francois Payette 2013-01-24 20:05:55 -05:00
parent a24102c237
commit 7d773508fc
2 changed files with 11 additions and 0 deletions

View File

@ -16,6 +16,8 @@ var parse = function(str) {
if(str.charAt(0) === '/') {
return { host: str };
}
// url parse expects spaces encoded as %20
str = str.replace(' ', '%20');
var result = url.parse(str);
var config = {};
config.host = result.hostname;

View File

@ -39,6 +39,15 @@ test('initializing from a config string', function() {
assert.equal(client.database, "databasename")
})
test('uses the correct values from the config string with space in password', function() {
var client = new Client("pg://brian:pass word@host1:333/databasename")
assert.equal(client.user, 'brian')
assert.equal(client.password, "pass word")
assert.equal(client.host, "host1")
assert.equal(client.port, 333)
assert.equal(client.database, "databasename")
})
test('when not including all values the defaults are used', function() {
var client = new Client("pg://host1")
assert.equal(client.user, process.env['PGUSER'] || process.env.USER)