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
5 changes: 3 additions & 2 deletions packages/pg-connection-string/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ function parse(str, options = {}) {
throw err
}

// We'd like to use Object.fromEntries() here but Node.js 10 does not support it
for (const entry of result.searchParams.entries()) {
// Like libpq, only percent-decode the query values: URLSearchParams would turn a literal
// `+` into a space. We'd like to use Object.fromEntries() here but Node.js 10 does not support it
for (const entry of new URLSearchParams(result.search.replace(/\+/g, '%2B')).entries()) {
config[entry[0]] = entry[1]
}

Expand Down
9 changes: 9 additions & 0 deletions packages/pg-connection-string/test/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ describe('parse', function () {
subject.fallback_application_name?.should.equal('TheAppFallback')
})

it('configuration parameters keep a literal plus sign', function () {
const connectionString = 'pg:///?application_name=a+b&user=c+d&password=e+f&options=g%2Bh%20i'
const subject = parse(connectionString)
subject.application_name?.should.equal('a+b')
subject.user?.should.equal('c+d')
subject.password?.should.equal('e+f')
subject.options?.should.equal('g+h i')
})

it('configuration parameter options', function () {
const connectionString = 'pg:///?options=-c geqo=off'
const subject = parse(connectionString)
Expand Down
Loading