Skip to content

Commit

Permalink
fix parse dsn
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyangxixian committed Dec 24, 2018
1 parent 881ca0d commit cfa5741
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,10 @@ func parseDSN(odbc string, d *dsn) *dsn {
userInfo = res[1]
hostInfo = res[2]
query = res[4]
} else {
} else if res := regexp.MustCompile(`^(.*?)($|\?)(.*)`).FindStringSubmatch(odbc); len(res) > 3 {
// hostInfo
hostInfo = odbc
hostInfo = res[1]
query = res[3]
}

// 解析用户信息
Expand Down
4 changes: 2 additions & 2 deletions common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func TestParseDSN(t *testing.T) {
"user:password@hostname:3307",
"user:password@hostname:/database",
"user:password@:3307/database",
"user@hostname/dbname",
"user:pwd:pwd@pwd/pwd@hostname/dbname",
"user@hostname/database",
"user:pwd:pwd@pwd/pwd@hostname/database",
"user:password@",
"hostname:3307/database",
"@hostname:3307/database",
Expand Down
4 changes: 2 additions & 2 deletions common/testdata/TestParseDSN.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
&common.dsn{Addr:"hostname:3307", Schema:"information_schema", User:"user", Password:"password", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"hostname:3306", Schema:"database", User:"user", Password:"password", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"127.0.0.1:3307", Schema:"database", User:"user", Password:"password", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"hostname:3306", Schema:"dbname", User:"user", Password:"", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"hostname:3306", Schema:"dbname", User:"user", Password:"pwd:pwd@pwd/pwd", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"hostname:3306", Schema:"database", User:"user", Password:"", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"hostname:3306", Schema:"database", User:"user", Password:"pwd:pwd@pwd/pwd", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"127.0.0.1:3306", Schema:"information_schema", User:"user", Password:"password", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"hostname:3307", Schema:"database", User:"", Password:"", Charset:"utf8mb4", Disable:false, Version:999}
&common.dsn{Addr:"hostname:3307", Schema:"database", User:"", Password:"", Charset:"utf8mb4", Disable:false, Version:999}
Expand Down

0 comments on commit cfa5741

Please sign in to comment.