mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
host= query param takes precedence
This commit is contained in:
parent
a483bdf5d9
commit
0ff40e733b
5
index.js
5
index.js
@ -35,7 +35,10 @@ function parse(str) {
|
||||
config.client_encoding = result.query.encoding;
|
||||
return config;
|
||||
}
|
||||
config.host = result.hostname;
|
||||
if (!config.host) {
|
||||
// Only set the host if there is no equivalent query param.
|
||||
config.host = result.hostname;
|
||||
}
|
||||
|
||||
// result.pathname is not always guaranteed to have a '/' prefix (e.g. relative urls)
|
||||
// only strip the slash if it is present.
|
||||
|
||||
@ -120,6 +120,19 @@ describe('parse', function(){
|
||||
(subject.database === null).should.equal(true);
|
||||
});
|
||||
|
||||
it('configuration parameter host', function() {
|
||||
var subject = parse('pg://user:pass@/dbname?host=/unix/socket');
|
||||
subject.user.should.equal('user');
|
||||
subject.password.should.equal('pass');
|
||||
subject.host.should.equal('/unix/socket');
|
||||
subject.database.should.equal('dbname');
|
||||
});
|
||||
|
||||
it('configuration parameter host overrides url host', function() {
|
||||
var subject = parse('pg://user:pass@localhost/dbname?host=/unix/socket');
|
||||
subject.host.should.equal('/unix/socket');
|
||||
});
|
||||
|
||||
it('configuration parameter application_name', function(){
|
||||
var connectionString = 'pg:///?application_name=TheApp';
|
||||
var subject = parse(connectionString);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user