Skip to content

Commit

Permalink
fixed issue where the password was being assigned to wrong config in …
Browse files Browse the repository at this point in the history
…case of empty
  • Loading branch information
ap-in-git committed Sep 26, 2023
1 parent e82f7d1 commit 0ae85f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,12 @@ func parseDSNSettings(s string) (map[string]string, error) {
}

key = strings.Trim(s[:eqIdx], " \t\n\r\v\f")
s = s[eqIdx+1:]

if s[0] == ' ' && s[1] != '\'' {
settings[key] = ""
continue
}
s = strings.TrimLeft(s[eqIdx+1:], " \t\n\r\v\f")
if len(s) == 0 {
} else if s[0] != '\'' {
Expand Down
13 changes: 13 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ func TestParseConfig(t *testing.T) {
RuntimeParams: map[string]string{},
},
},
{
name: "DNS with empty password",
connString: "host=localhost user=jack password= dbname=mydb port=5432 sslmode=disable ",
config: &pgconn.Config{
User: "jack",
Host: "localhost",
Port: 5432,
Password: "",
Database: "mydb",
TLSConfig: nil,
RuntimeParams: map[string]string{},
},
},
{
name: "sslmode allow",
connString: "postgres://jack:secret@localhost:5432/mydb?sslmode=allow",
Expand Down

0 comments on commit 0ae85f7

Please sign in to comment.