Skip to content

Commit

Permalink
Fix: Postgres fails to connect when using special characters (1Panel-…
Browse files Browse the repository at this point in the history
  • Loading branch information
lan-yonghui authored Dec 6, 2024
1 parent 3e14186 commit 873bba9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/utils/postgresql/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"net/url"
"time"

"github.com/1Panel-dev/1Panel/backend/buserr"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 873bba9

Please sign in to comment.