Skip to content

Commit 7d19fca

Browse files
committed
Improve a bit more upon work done in hashicorp#10922 and only return a quoted
string if there is whitespace present. Aesthetics. What can I say.
1 parent d92a3ca commit 7d19fca

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

builtin/providers/postgresql/config.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"database/sql"
66
"fmt"
77
"log"
8+
"unicode"
89

910
_ "github.com/lib/pq" //PostgreSQL db
1011
)
@@ -38,7 +39,12 @@ func (c *Config) NewClient() (*Client, error) {
3839
q := func(s string) string {
3940
b := bytes.NewBufferString(`'`)
4041
b.Grow(len(s) + 2)
42+
var haveWhitespace bool
4143
for _, r := range s {
44+
if unicode.IsSpace(r) {
45+
haveWhitespace = true
46+
}
47+
4248
switch r {
4349
case '\'':
4450
b.WriteString(`\'`)
@@ -50,7 +56,12 @@ func (c *Config) NewClient() (*Client, error) {
5056
}
5157

5258
b.WriteString(`'`)
53-
return b.String()
59+
60+
str := b.String()
61+
if haveWhitespace {
62+
return str
63+
}
64+
return str[1 : len(str)-1]
5465
}
5566

5667
logDSN := fmt.Sprintf(dsnFmt, q(c.Host), c.Port, q(c.Database), q(c.Username), q("<redacted>"), q(c.SSLMode), q(c.ApplicationName), c.ConnectTimeoutSec)

0 commit comments

Comments
 (0)