fix(database/gdb): #3755 error parsing database link without port number (#3772)

This commit is contained in:
John Guo 2024-09-13 16:50:59 +08:00 committed by GitHub
parent 4ee5bf5c45
commit 6a99931798
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 5 deletions

View File

@ -276,12 +276,18 @@ func parseConfigNodeLink(node *ConfigNode) *ConfigNode {
node.Pass = match[3]
node.Protocol = match[4]
array := gstr.Split(match[5], ":")
if len(array) == 2 && node.Protocol != "file" {
node.Host = array[0]
node.Port = array[1]
node.Name = match[6]
} else {
if node.Protocol == "file" {
node.Name = match[5]
} else {
if len(array) == 2 {
// link with port.
node.Host = array[0]
node.Port = array[1]
} else {
// link without port.
node.Host = array[0]
}
node.Name = match[6]
}
if len(match) > 6 && match[7] != "" {
node.Extra = match[7]

View File

@ -232,6 +232,22 @@ func Test_parseConfigNodeLink_WithType(t *testing.T) {
t.Assert(newNode.Charset, defaultCharset)
t.Assert(newNode.Protocol, `tcp`)
})
// #3755
gtest.C(t, func(t *gtest.T) {
node := &ConfigNode{
Link: "mysql:user:pwd@tcp(rdsid.mysql.rds.aliyuncs.com)/dbname?charset=utf8&loc=Local",
}
newNode := parseConfigNodeLink(node)
t.Assert(newNode.Type, `mysql`)
t.Assert(newNode.User, `user`)
t.Assert(newNode.Pass, `pwd`)
t.Assert(newNode.Host, `rdsid.mysql.rds.aliyuncs.com`)
t.Assert(newNode.Port, ``)
t.Assert(newNode.Name, `dbname`)
t.Assert(newNode.Extra, `charset=utf8&loc=Local`)
t.Assert(newNode.Charset, `utf8`)
t.Assert(newNode.Protocol, `tcp`)
})
}
func Test_Func_doQuoteWord(t *testing.T) {