From 7d773508fc2e93d0a6447e407e09e7c37d495de4 Mon Sep 17 00:00:00 2001 From: Francois Payette Date: Thu, 24 Jan 2013 20:05:55 -0500 Subject: [PATCH] replace space by %20 in connection string before passing to url.parse --- lib/connection-parameters.js | 2 ++ test/unit/client/configuration-tests.js | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index 5a6dc431..05305a81 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -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; diff --git a/test/unit/client/configuration-tests.js b/test/unit/client/configuration-tests.js index 7d09fa1e..79e29c18 100644 --- a/test/unit/client/configuration-tests.js +++ b/test/unit/client/configuration-tests.js @@ -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)