Skip to content

Commit 7240643

Browse files
authored
fix(postgres): update connection string handling for optional port (#326)
1 parent 85b0810 commit 7240643

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

postgres/pg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports._queryWithConnectionString = async function(query, connectionString) {
1414
}
1515

1616
function encodePasswordInConnectionString(connectionString) {
17-
const regex = /^(postgresql:\/\/)([^:]+):([^@]+)@([^:\/]+):(\d+)\/(.+)$/;
17+
const regex = /^(postgresql:\/\/)([^:]+):([^@]+)@([^:\/]+)(:\d+)?\/(.+)$/;
1818
const match = connectionString.match(regex);
1919

2020
if (!match) {
@@ -25,7 +25,7 @@ function encodePasswordInConnectionString(connectionString) {
2525

2626
const encodedPassword = encodeURIComponent(password);
2727

28-
return `${protocol}${username}:${encodedPassword}@${host}:${port}/${database}`;
28+
return `${protocol}${username}:${encodedPassword}@${host}${port ?? ""}/${database}`;
2929
}
3030

3131
// workaround for readiness probe

0 commit comments

Comments
 (0)