Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pg-connection-string/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function parse(str, options = {}) {
config.client_encoding = result.searchParams.get('encoding')
return config
}
const hostname = dummyHost ? '' : result.hostname
const hostname = (dummyHost ? '' : result.hostname).replace(/^\[(.+)\]$/, '$1')
if (!config.host) {
// Only set the host if there is no equivalent query param.
config.host = decodeURIComponent(hostname)
Expand Down
5 changes: 5 additions & 0 deletions packages/pg-connection-string/test/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ describe('parse', function () {
subject.database?.should.equal('lala')
})

it('strips the URI brackets from an IPv6 host', function () {
parse('postgres://brian:pw@[::1]:5432/lala').host?.should.equal('::1')
parse('postgres://brian:pw@[2001:db8::1]:5432/lala').host?.should.equal('2001:db8::1')
})

it('escape spaces if present', function () {
const subject = parse('postgres://localhost/post gres')
subject.database?.should.equal('post gres')
Expand Down
Loading