Skip to content

Commit bf0c4bf

Browse files
committed
Merge branch 'pull/326'
Conflicts: lib/connection-parameters.js test/unit/connection-parameters/creation-tests.js
2 parents 3bd5e69 + b6ef157 commit bf0c4bf

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Diff for: lib/connection-parameters.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ var parse = function(str) {
2727
return { host: config[0], database: config[1] };
2828
}
2929
// url parse expects spaces encoded as %20
30-
if(/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) str = encodeURI(str);
30+
if(/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) {
31+
str = encodeURI(str).replace(/\%25(\d\d)/g, "%$1");
32+
}
3133
var result = url.parse(str, true);
3234
config = {};
3335

Diff for: test/unit/connection-parameters/creation-tests.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,26 @@ test('libpq connection string building', function() {
184184
assert.equal(subject.password, sourceConfig.password);
185185
});
186186

187-
test('password contains weird characters', function() {
187+
test('username or password contains weird characters', function() {
188188
var defaults = require('../../../lib/defaults');
189189
defaults.ssl = true;
190-
var strang = 'postgres://my first name:is&%awesome!@localhost:9000';
190+
var strang = 'pg://my f%irst name:is&%awesome!@localhost:9000';
191191
var subject = new ConnectionParameters(strang);
192-
assert.equal(subject.user, 'my first name');
192+
assert.equal(subject.user, 'my f%irst name');
193193
assert.equal(subject.password, 'is&%awesome!');
194194
assert.equal(subject.host, 'localhost');
195195
assert.equal(subject.ssl, true);
196196
});
197197

198+
test("url is properly encoded", function() {
199+
var encoded = "pg://bi%25na%25%25ry%20:s%40f%23@localhost/%20u%2520rl";
200+
var subject = new ConnectionParameters(encoded);
201+
assert.equal(subject.user, "bi%na%%ry ");
202+
assert.equal(subject.password, "s@f#");
203+
assert.equal(subject.host, 'localhost');
204+
assert.equal(subject.database, " u%20rl");
205+
});
206+
198207
test('ssl is set on client', function() {
199208
var Client = require('../../../lib/client')
200209
var defaults = require('../../../lib/defaults');

0 commit comments

Comments
 (0)