Skip to content

Commit d3dead4

Browse files
committed
pg-connection-string: avoid clobbering port from queryparams
If the connection string is something like: postgresql://demo:password@/postgres?host=localhost&port=26258 Then the port from the query parameters should be used. Previously, the parsing function would end up with a null port, and the default port would end up being used by the connecetion package.
1 parent 9dfb3dc commit d3dead4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/pg-connection-string/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function parse(str) {
3131
config.user = auth[0]
3232
config.password = auth.splice(1).join(':')
3333

34-
config.port = result.port
3534
if (result.protocol == 'socket:') {
3635
config.host = decodeURI(result.pathname)
3736
config.database = result.query.db
@@ -42,6 +41,10 @@ function parse(str) {
4241
// Only set the host if there is no equivalent query param.
4342
config.host = result.hostname
4443
}
44+
if (!config.port) {
45+
// Only set the port if there is no equivalent query param.
46+
config.port = result.port
47+
}
4548

4649
// If the host is missing it might be a URL-encoded path to a socket.
4750
var pathname = result.pathname

0 commit comments

Comments
 (0)