From e007bf35b2747f2d3c6ce145a26d370842ad1727 Mon Sep 17 00:00:00 2001 From: Sany Date: Thu, 22 Dec 2022 17:33:51 +0800 Subject: [PATCH] parseConfigNodeLink support Chinese database name #2231 (#2238) --- contrib/drivers/mysql/mysql_issue_test.go | 20 ++++++++++++++++++++ database/gdb/gdb.go | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/contrib/drivers/mysql/mysql_issue_test.go b/contrib/drivers/mysql/mysql_issue_test.go index c1dd38695..40e78b85a 100644 --- a/contrib/drivers/mysql/mysql_issue_test.go +++ b/contrib/drivers/mysql/mysql_issue_test.go @@ -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" @@ -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") + }) +} diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index 6222d3d45..04eabb8cb 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -316,7 +316,7 @@ const ( ctxKeyInternalProducedSQL gctx.StrKey = `CtxKeyInternalProducedSQL` // type:[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN] - linkPattern = `(\w+):([\w\-]*):(.*?)@(\w+?)\((.+?)\)/{0,1}([\w\-]*)\?{0,1}(.*)` + linkPattern = `(\w+):([\w\-]*):(.*?)@(\w+?)\((.+?)\)/{0,1}([^\?]*)\?{0,1}(.*)` ) const (