Skip to content

Commit

Permalink
fixed escaping for postgresql user info (#344)
Browse files Browse the repository at this point in the history
(cherry picked from commit e15fd44)

Co-authored-by: Cyril Gaudin <[email protected]>
  • Loading branch information
librucha and cyrilgdn authored Sep 10, 2023
1 parent e7499ce commit a961e75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions postgresql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"unicode"

"github.com/blang/semver"
_ "github.com/lib/pq" //PostgreSQL db
_ "github.com/lib/pq" // PostgreSQL db
"gocloud.dev/postgres"
_ "gocloud.dev/postgres/awspostgres"
_ "gocloud.dev/postgres/gcppostgres"
Expand Down Expand Up @@ -247,8 +247,8 @@ func (c *Config) connStr(database string) string {
connStr := fmt.Sprintf(
"%s://%s:%s@%s:%d/%s?%s",
c.Scheme,
url.QueryEscape(c.Username),
url.QueryEscape(c.Password),
url.PathEscape(c.Username),
url.PathEscape(c.Password),
host,
c.Port,
database,
Expand Down Expand Up @@ -304,7 +304,7 @@ func (c *Client) Connect() (*DBConnection, error) {
// Version hint not set by user, need to fingerprint
version, err = fingerprintCapabilities(db)
if err != nil {
db.Close()
_ = db.Close()
return nil, fmt.Errorf("error detecting capabilities: %w", err)
}
}
Expand Down
1 change: 1 addition & 0 deletions postgresql/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestConfigConnStr(t *testing.T) {
wantDbParams []string
}{
{&Config{Scheme: "postgres", Host: "localhost", Port: 5432, Username: "postgres_user", Password: "postgres_password", SSLMode: "disable"}, "postgres://postgres_user:postgres_password@localhost:5432/postgres", []string{"connect_timeout=0", "sslmode=disable"}},
{&Config{Scheme: "postgres", Host: "localhost", Port: 5432, Username: "spaced user", Password: "spaced password", SSLMode: "disable"}, "postgres://spaced%20user:spaced%20password@localhost:5432/postgres", []string{"connect_timeout=0", "sslmode=disable"}},
}

for _, test := range tests {
Expand Down

0 comments on commit a961e75

Please sign in to comment.