Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(database/gdb): regular expression pattern for link configuration to be compitable with tidbcloud #4064

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion database/gdb/gdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ const (
ctxKeyCatchSQL gctx.StrKey = `CtxKeyCatchSQL`
ctxKeyInternalProducedSQL gctx.StrKey = `CtxKeyInternalProducedSQL`

linkPattern = `(\w+):([\w\-\$]*):(.*?)@(\w+?)\((.+?)\)/{0,1}([^\?]*)\?{0,1}(.*)`
linkPattern = `^(\w+):(.*?):(.*?)@(\w+?)\((.+?)\)/{0,1}([^\?]*)\?{0,1}(.*?)$`
linkPatternDescription = `type:username:password@protocol(host:port)/dbname?param1=value1&...&paramN=valueN`
)

Expand Down
34 changes: 34 additions & 0 deletions database/gdb/gdb_z_mysql_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,40 @@ func Test_parseConfigNodeLink_WithType(t *testing.T) {
t.Assert(newNode.Charset, `utf8`)
t.Assert(newNode.Protocol, `unix`)
})
// https://github.com/gogf/gf/issues/4059
gtest.C(t, func(t *gtest.T) {
node := &ConfigNode{
Link: "tidb:2hcmRccccxxx9Fizz.root:wP3xxxxPIDc@tcp(xxxx.tidbcloud.com:4000)/db_name?tls=true",
}
newNode, err := parseConfigNodeLink(node)
t.AssertNil(err)
t.Assert(newNode.Type, `tidb`)
t.Assert(newNode.User, `2hcmRccccxxx9Fizz.root`)
t.Assert(newNode.Pass, `wP3xxxxPIDc`)
t.Assert(newNode.Host, `xxxx.tidbcloud.com`)
t.Assert(newNode.Port, `4000`)
t.Assert(newNode.Name, `db_name`)
t.Assert(newNode.Extra, `tls=true`)
t.Assert(newNode.Charset, `utf8`)
t.Assert(newNode.Protocol, `tcp`)
})
gtest.C(t, func(t *gtest.T) {
node := &ConfigNode{
Type: "tidb",
Link: "2hcmRccccxxx9Fizz.root:wP3xxxxPIDc@tcp(xxxx.tidbcloud.com:4000)/db_name?tls=true",
}
newNode, err := parseConfigNodeLink(node)
t.AssertNil(err)
t.Assert(newNode.Type, `tidb`)
t.Assert(newNode.User, `2hcmRccccxxx9Fizz.root`)
t.Assert(newNode.Pass, `wP3xxxxPIDc`)
t.Assert(newNode.Host, `xxxx.tidbcloud.com`)
t.Assert(newNode.Port, `4000`)
t.Assert(newNode.Name, `db_name`)
t.Assert(newNode.Extra, `tls=true`)
t.Assert(newNode.Charset, `utf8`)
t.Assert(newNode.Protocol, `tcp`)
})
}

func Test_Func_doQuoteWord(t *testing.T) {
Expand Down
Loading