mirror of https://github.com/1Panel-dev/1Panel
Fix: Postgres fails to connect when using special characters (#7269)
parent
3e14186d3d
commit
873bba92db
|
@ -5,6 +5,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/buserr"
|
"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
|
// Escape username and password to handle special characters
|
||||||
escapedUsername := url.QueryEscape(username)
|
escapedUsername := url.QueryEscape(conn.Username)
|
||||||
escapedPassword := url.QueryEscape(password)
|
escapedPassword := url.QueryEscape(conn.Password)
|
||||||
|
|
||||||
connArgs := fmt.Sprintf("postgres://%s:%s@%s:%d/?sslmode=disable", escapedUsername, escapedPassword, conn.Address, conn.Port)
|
connArgs := fmt.Sprintf("postgres://%s:%s@%s:%d/?sslmode=disable", escapedUsername, escapedPassword, conn.Address, conn.Port)
|
||||||
db, err := sql.Open("pgx", connArgs)
|
db, err := sql.Open("pgx", connArgs)
|
||||||
|
|
Loading…
Reference in New Issue