diff --git a/rules/common/domain.go b/rules/common/domain.go index f52f1f23..5638afe1 100644 --- a/rules/common/domain.go +++ b/rules/common/domain.go @@ -1,6 +1,7 @@ package common import ( + "golang.org/x/net/idna" "strings" C "github.com/Dreamacro/clash/constant" @@ -8,8 +9,9 @@ import ( type Domain struct { *Base - domain string - adapter string + domain string + rawDomain string + adapter string } func (d *Domain) RuleType() C.RuleType { @@ -28,14 +30,16 @@ func (d *Domain) Adapter() string { } func (d *Domain) Payload() string { - return d.domain + return d.rawDomain } func NewDomain(domain string, adapter string) *Domain { + actualDomain, _ := idna.ToASCII(domain) return &Domain{ - Base: &Base{}, - domain: strings.ToLower(domain), - adapter: adapter, + Base: &Base{}, + domain: strings.ToLower(actualDomain), + adapter: adapter, + rawDomain: domain, } } diff --git a/rules/common/domain_keyword.go b/rules/common/domain_keyword.go index ea9f5703..c13dcdbf 100644 --- a/rules/common/domain_keyword.go +++ b/rules/common/domain_keyword.go @@ -1,6 +1,7 @@ package common import ( + "golang.org/x/net/idna" "strings" C "github.com/Dreamacro/clash/constant" @@ -8,8 +9,9 @@ import ( type DomainKeyword struct { *Base - keyword string - adapter string + keyword string + adapter string + rawKeyword string } func (dk *DomainKeyword) RuleType() C.RuleType { @@ -29,14 +31,16 @@ func (dk *DomainKeyword) Adapter() string { } func (dk *DomainKeyword) Payload() string { - return dk.keyword + return dk.rawKeyword } func NewDomainKeyword(keyword string, adapter string) *DomainKeyword { + actualDomainKeyword, _ := idna.ToASCII(keyword) return &DomainKeyword{ - Base: &Base{}, - keyword: strings.ToLower(keyword), - adapter: adapter, + Base: &Base{}, + keyword: strings.ToLower(actualDomainKeyword), + adapter: adapter, + rawKeyword: keyword, } } diff --git a/rules/common/domain_suffix.go b/rules/common/domain_suffix.go index dd350983..278052f2 100644 --- a/rules/common/domain_suffix.go +++ b/rules/common/domain_suffix.go @@ -1,6 +1,7 @@ package common import ( + "golang.org/x/net/idna" "strings" C "github.com/Dreamacro/clash/constant" @@ -8,8 +9,9 @@ import ( type DomainSuffix struct { *Base - suffix string - adapter string + suffix string + adapter string + rawSuffix string } func (ds *DomainSuffix) RuleType() C.RuleType { @@ -29,14 +31,16 @@ func (ds *DomainSuffix) Adapter() string { } func (ds *DomainSuffix) Payload() string { - return ds.suffix + return ds.rawSuffix } func NewDomainSuffix(suffix string, adapter string) *DomainSuffix { + actualDomainKeyword, _ := idna.ToASCII(suffix) return &DomainSuffix{ - Base: &Base{}, - suffix: strings.ToLower(suffix), - adapter: adapter, + Base: &Base{}, + suffix: strings.ToLower(actualDomainKeyword), + adapter: adapter, + rawSuffix: suffix, } } diff --git a/rules/provider/domain_strategy.go b/rules/provider/domain_strategy.go index 9b1a49af..a6145383 100644 --- a/rules/provider/domain_strategy.go +++ b/rules/provider/domain_strategy.go @@ -4,6 +4,7 @@ import ( "github.com/Dreamacro/clash/component/trie" C "github.com/Dreamacro/clash/constant" "github.com/Dreamacro/clash/log" + "golang.org/x/net/idna" ) type domainStrategy struct { @@ -27,7 +28,8 @@ func (d *domainStrategy) OnUpdate(rules []string) { domainTrie := trie.New[bool]() count := 0 for _, rule := range rules { - err := domainTrie.Insert(rule, true) + actualDomain, _ := idna.ToASCII(rule) + err := domainTrie.Insert(actualDomain, true) if err != nil { log.Warnln("invalid domain:[%s]", rule) } else {