Skip to content

Commit

Permalink
parseConfigNodeLink support Chinese database name #2231 (#2238)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanrentai authored Dec 22, 2022
1 parent 74e968e commit e007bf3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions contrib/drivers/mysql/mysql_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gmeta"
"github.com/gogf/gf/v2/util/guid"
Expand Down Expand Up @@ -456,3 +457,22 @@ func Test_Issue2105(t *testing.T) {
t.Assert(len(list[1].Json), 3)
})
}

// https://github.com/gogf/gf/issues/2231
func Test_Issue2231(t *testing.T) {
linkPattern := `(\w+):([\w\-]*):(.*?)@(\w+?)\((.+?)\)/{0,1}([^\?]*)\?{0,1}(.*)`
link := `mysql:root:12345678@tcp(127.0.0.1:3306)/a正bc式?loc=Local&parseTime=true`

gtest.C(t, func(t *gtest.T) {

match, err := gregex.MatchString(linkPattern, link)
t.AssertNil(err)
t.Assert(match[1], "mysql")
t.Assert(match[2], "root")
t.Assert(match[3], "12345678")
t.Assert(match[4], "tcp")
t.Assert(match[5], "127.0.0.1:3306")
t.Assert(match[6], "a正bc式")
t.Assert(match[7], "loc=Local&parseTime=true")
})
}
2 changes: 1 addition & 1 deletion database/gdb/gdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ const (
ctxKeyInternalProducedSQL gctx.StrKey = `CtxKeyInternalProducedSQL`

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

const (
Expand Down

0 comments on commit e007bf3

Please sign in to comment.