From f796dc59216ba46ef16f5e6b585aa1b49931128e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 7 Sep 2022 17:08:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=AD=E6=96=87=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=EF=BC=88=E8=BD=AC=E6=8D=A2punycode=E5=90=8E=EF=BC=89?= =?UTF-8?q?=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/serverconfigs/server_config.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/serverconfigs/server_config.go b/pkg/serverconfigs/server_config.go index 4c731e3..1e6c6dd 100644 --- a/pkg/serverconfigs/server_config.go +++ b/pkg/serverconfigs/server_config.go @@ -6,8 +6,12 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/configutils" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs" + "golang.org/x/net/idna" + "regexp" ) +var normalServerNameReg = regexp.MustCompile(`^[a-zA-Z0-9.-]+$`) + type ServerConfig struct { Id int64 `yaml:"id" json:"id"` // ID ClusterId int64 `yaml:"clusterId" json:"clusterId"` // 集群ID @@ -341,6 +345,14 @@ func (this *ServerConfig) AllStrictNames() []string { if len(name) > 0 { if !configutils.IsFuzzyDomain(name) { result = append(result, name) + + // unicode domain + if !normalServerNameReg.MatchString(name) { + asciiName, err := idna.ToASCII(name) + if err == nil && len(asciiName) > 0 { + result = append(result, asciiName) + } + } } } } @@ -349,12 +361,28 @@ func (this *ServerConfig) AllStrictNames() []string { if len(name) > 0 { if !configutils.IsFuzzyDomain(name) { result = append(result, name) + + // unicode domain + if !normalServerNameReg.MatchString(name) { + asciiName, err := idna.ToASCII(name) + if err == nil && len(asciiName) > 0 { + result = append(result, asciiName) + } + } } } for _, name := range serverName.SubNames { if len(name) > 0 { if !configutils.IsFuzzyDomain(name) { result = append(result, name) + + // unicode domain + if !normalServerNameReg.MatchString(name) { + asciiName, err := idna.ToASCII(name) + if err == nil && len(asciiName) > 0 { + result = append(result, asciiName) + } + } } } }