From 0ae85f7c0d8c694eec051ded9b8097fdb64847de Mon Sep 17 00:00:00 2001 From: ashok Date: Tue, 26 Sep 2023 01:26:39 -0400 Subject: [PATCH] fixed issue where the password was being assigned to wrong config in case of empty --- config.go | 6 ++++++ config_test.go | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/config.go b/config.go index 36b74c4..839bcbc 100644 --- a/config.go +++ b/config.go @@ -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] != '\'' { diff --git a/config_test.go b/config_test.go index 629b5c0..f0a85c2 100644 --- a/config_test.go +++ b/config_test.go @@ -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",