From 7d19fcae254ef66f97e5601d7dea45efb735604b Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Sun, 25 Dec 2016 06:19:14 -0800 Subject: [PATCH] Improve a bit more upon work done in #10922 and only return a quoted string if there is whitespace present. Aesthetics. What can I say. --- builtin/providers/postgresql/config.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/builtin/providers/postgresql/config.go b/builtin/providers/postgresql/config.go index 61b7f4cd5..5a251e69d 100644 --- a/builtin/providers/postgresql/config.go +++ b/builtin/providers/postgresql/config.go @@ -5,6 +5,7 @@ import ( "database/sql" "fmt" "log" + "unicode" _ "github.com/lib/pq" //PostgreSQL db ) @@ -38,7 +39,12 @@ func (c *Config) NewClient() (*Client, error) { q := func(s string) string { b := bytes.NewBufferString(`'`) b.Grow(len(s) + 2) + var haveWhitespace bool for _, r := range s { + if unicode.IsSpace(r) { + haveWhitespace = true + } + switch r { case '\'': b.WriteString(`\'`) @@ -50,7 +56,12 @@ func (c *Config) NewClient() (*Client, error) { } b.WriteString(`'`) - return b.String() + + str := b.String() + if haveWhitespace { + return str + } + return str[1 : len(str)-1] } logDSN := fmt.Sprintf(dsnFmt, q(c.Host), c.Port, q(c.Database), q(c.Username), q(""), q(c.SSLMode), q(c.ApplicationName), c.ConnectTimeoutSec)