File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,10 @@ function parse(str) {
3535 config . client_encoding = result . query . encoding ;
3636 return config ;
3737 }
38- config . host = result . hostname ;
38+ if ( ! config . host ) {
39+ // Only set the host if there is no equivalent query param.
40+ config . host = result . hostname ;
41+ }
3942
4043 // result.pathname is not always guaranteed to have a '/' prefix (e.g. relative urls)
4144 // only strip the slash if it is present.
Original file line number Diff line number Diff line change @@ -120,6 +120,19 @@ describe('parse', function(){
120120 ( subject . database === null ) . should . equal ( true ) ;
121121 } ) ;
122122
123+ it ( 'configuration parameter host' , function ( ) {
124+ var subject = parse ( 'pg://user:pass@/dbname?host=/unix/socket' ) ;
125+ subject . user . should . equal ( 'user' ) ;
126+ subject . password . should . equal ( 'pass' ) ;
127+ subject . host . should . equal ( '/unix/socket' ) ;
128+ subject . database . should . equal ( 'dbname' ) ;
129+ } ) ;
130+
131+ it ( 'configuration parameter host overrides url host' , function ( ) {
132+ var subject = parse ( 'pg://user:pass@localhost/dbname?host=/unix/socket' ) ;
133+ subject . host . should . equal ( '/unix/socket' ) ;
134+ } ) ;
135+
123136 it ( 'configuration parameter application_name' , function ( ) {
124137 var connectionString = 'pg:///?application_name=TheApp' ;
125138 var subject = parse ( connectionString ) ;
You can’t perform that action at this time.
0 commit comments