From 873bba92db58844a714a6a3c8bdfa536de80c8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=98=AD?= <81747598+lan-yonghui@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:19:41 +0800 Subject: [PATCH] Fix: Postgres fails to connect when using special characters (#7269) --- backend/utils/postgresql/client.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/utils/postgresql/client.go b/backend/utils/postgresql/client.go index 125588752..98dd124a9 100644 --- a/backend/utils/postgresql/client.go +++ b/backend/utils/postgresql/client.go @@ -5,6 +5,7 @@ import ( "database/sql" "errors" "fmt" + "net/url" "time" "github.com/1Panel-dev/1Panel/backend/buserr" @@ -33,8 +34,8 @@ func NewPostgresqlClient(conn client.DBInfo) (PostgresqlClient, error) { } // Escape username and password to handle special characters - escapedUsername := url.QueryEscape(username) - escapedPassword := url.QueryEscape(password) + escapedUsername := url.QueryEscape(conn.Username) + escapedPassword := url.QueryEscape(conn.Password) connArgs := fmt.Sprintf("postgres://%s:%s@%s:%d/?sslmode=disable", escapedUsername, escapedPassword, conn.Address, conn.Port) db, err := sql.Open("pgx", connArgs)