Skip to content

Commit

Permalink
fixed escaping for postgresql user info
Browse files Browse the repository at this point in the history
  • Loading branch information
librucha committed Aug 14, 2023
1 parent fea83f3 commit e15fd44
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 @@ -241,8 +241,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 @@ -298,7 +298,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 e15fd44

Please sign in to comment.