Skip to content

Commit 6a99931

Browse files
authored
fix(database/gdb): #3755 error parsing database link without port number (#3772)
1 parent 4ee5bf5 commit 6a99931

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

database/gdb/gdb_core_config.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,18 @@ func parseConfigNodeLink(node *ConfigNode) *ConfigNode {
276276
node.Pass = match[3]
277277
node.Protocol = match[4]
278278
array := gstr.Split(match[5], ":")
279-
if len(array) == 2 && node.Protocol != "file" {
280-
node.Host = array[0]
281-
node.Port = array[1]
282-
node.Name = match[6]
283-
} else {
279+
if node.Protocol == "file" {
284280
node.Name = match[5]
281+
} else {
282+
if len(array) == 2 {
283+
// link with port.
284+
node.Host = array[0]
285+
node.Port = array[1]
286+
} else {
287+
// link without port.
288+
node.Host = array[0]
289+
}
290+
node.Name = match[6]
285291
}
286292
if len(match) > 6 && match[7] != "" {
287293
node.Extra = match[7]

database/gdb/gdb_z_mysql_internal_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,22 @@ func Test_parseConfigNodeLink_WithType(t *testing.T) {
232232
t.Assert(newNode.Charset, defaultCharset)
233233
t.Assert(newNode.Protocol, `tcp`)
234234
})
235+
// #3755
236+
gtest.C(t, func(t *gtest.T) {
237+
node := &ConfigNode{
238+
Link: "mysql:user:pwd@tcp(rdsid.mysql.rds.aliyuncs.com)/dbname?charset=utf8&loc=Local",
239+
}
240+
newNode := parseConfigNodeLink(node)
241+
t.Assert(newNode.Type, `mysql`)
242+
t.Assert(newNode.User, `user`)
243+
t.Assert(newNode.Pass, `pwd`)
244+
t.Assert(newNode.Host, `rdsid.mysql.rds.aliyuncs.com`)
245+
t.Assert(newNode.Port, ``)
246+
t.Assert(newNode.Name, `dbname`)
247+
t.Assert(newNode.Extra, `charset=utf8&loc=Local`)
248+
t.Assert(newNode.Charset, `utf8`)
249+
t.Assert(newNode.Protocol, `tcp`)
250+
})
235251
}
236252

237253
func Test_Func_doQuoteWord(t *testing.T) {

0 commit comments

Comments
 (0)