mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
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 <pete@bacondarwin.com> --------- Co-authored-by: Brian C <brian.m.carlson@gmail.com> Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>
This commit is contained in:
parent
65406985b9
commit
c38ecf3405
@ -49,7 +49,8 @@ function parse(str) {
|
||||
if (!config.host) {
|
||||
// Only set the host if there is no equivalent query param.
|
||||
config.host = decodeURIComponent(hostname)
|
||||
} else if (hostname) {
|
||||
} else if (hostname && /^%2f/i.test(hostname)) {
|
||||
// Only prepend the hostname to the pathname if it is not a URL encoded Unix socket host.
|
||||
result.pathname = hostname + result.pathname
|
||||
}
|
||||
|
||||
|
||||
@ -149,6 +149,7 @@ describe('parse', function () {
|
||||
|
||||
it('configuration parameter host overrides url host', function () {
|
||||
var subject = parse('pg://user:pass@localhost/dbname?host=/unix/socket')
|
||||
subject.database.should.equal('dbname')
|
||||
subject.host.should.equal('/unix/socket')
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user