Skip to content
This repository was archived by the owner on Oct 8, 2018. It is now read-only.

Commit 1007344

Browse files
author
David Wilkins
committed
Fixes: #7 - don't escape username and password
Signed-off-by: David Wilkins <[email protected]>
1 parent 55ff643 commit 1007344

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

connector.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ func (c *SQLConnection) GetDatabase() *sqlx.DB {
8181
}
8282

8383
var err error
84+
85+
userinfo := c.URL.User.Username()
86+
if password, hasPassword := c.URL.User.Password(); hasPassword {
87+
userinfo = userinfo + ":" + password
88+
}
89+
c.URL.User = nil
8490
clean := cleanURLQuery(c.URL)
8591

8692
if err = retry(c.L, time.Second*15, time.Minute*2, func() error {
@@ -91,12 +97,13 @@ func (c *SQLConnection) GetDatabase() *sqlx.DB {
9197
q.Set("parseTime", "true")
9298
clean.RawQuery = q.Encode()
9399
}
94-
95100
u := clean.String()
101+
if strings.HasPrefix(u, clean.Scheme+"://") {
102+
u = strings.Replace(u, clean.Scheme+"://", clean.Scheme+"://"+userinfo+"@", 1)
103+
}
96104
if clean.Scheme == "mysql" {
97105
u = strings.Replace(u, "mysql://", "", -1)
98106
}
99-
100107
if c.db, err = sqlx.Open(clean.Scheme, u); err != nil {
101108
return errors.Errorf("Could not Connect to SQL: %s", err)
102109
} else if err := c.db.Ping(); err != nil {

0 commit comments

Comments
 (0)