Skip to content

Commit 873bba9

Browse files
authored
Fix: Postgres fails to connect when using special characters (#7269)
1 parent 3e14186 commit 873bba9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

backend/utils/postgresql/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"database/sql"
66
"errors"
77
"fmt"
8+
"net/url"
89
"time"
910

1011
"github.com/1Panel-dev/1Panel/backend/buserr"
@@ -33,8 +34,8 @@ func NewPostgresqlClient(conn client.DBInfo) (PostgresqlClient, error) {
3334
}
3435

3536
// Escape username and password to handle special characters
36-
escapedUsername := url.QueryEscape(username)
37-
escapedPassword := url.QueryEscape(password)
37+
escapedUsername := url.QueryEscape(conn.Username)
38+
escapedPassword := url.QueryEscape(conn.Password)
3839

3940
connArgs := fmt.Sprintf("postgres://%s:%s@%s:%d/?sslmode=disable", escapedUsername, escapedPassword, conn.Address, conn.Port)
4041
db, err := sql.Open("pgx", connArgs)

0 commit comments

Comments
 (0)