Skip to content

Commit c38ecf3

Browse files
domdomeggbriancpetebacondarwin
authored
Fix connection string parsing for overriden hosts (#2977)
* Add failing test * Fix test This corresponds to what was line 48 previously, see https://github.com/brianc/node-postgres/pull/2971/files#diff-08a5e82487ebd9b43751630019753901fae0a111f8d009ad2e9d194445e96922L48 * Update packages/pg-connection-string/index.js Co-authored-by: Pete Bacon Darwin <[email protected]> --------- Co-authored-by: Brian C <[email protected]> Co-authored-by: Pete Bacon Darwin <[email protected]>
1 parent 6540698 commit c38ecf3

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

packages/pg-connection-string/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ function parse(str) {
4949
if (!config.host) {
5050
// Only set the host if there is no equivalent query param.
5151
config.host = decodeURIComponent(hostname)
52-
} else if (hostname) {
52+
} else if (hostname && /^%2f/i.test(hostname)) {
53+
// Only prepend the hostname to the pathname if it is not a URL encoded Unix socket host.
5354
result.pathname = hostname + result.pathname
5455
}
5556

packages/pg-connection-string/test/parse.js

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ describe('parse', function () {
149149

150150
it('configuration parameter host overrides url host', function () {
151151
var subject = parse('pg://user:pass@localhost/dbname?host=/unix/socket')
152+
subject.database.should.equal('dbname')
152153
subject.host.should.equal('/unix/socket')
153154
})
154155

0 commit comments

Comments
 (0)