fix: IDNA domain match

This commit is contained in:
gVisor bot 2022-06-18 18:13:54 +08:00
parent 5e61947d84
commit eebac64086
4 changed files with 33 additions and 19 deletions

View File

@ -1,6 +1,7 @@
package common
import (
"golang.org/x/net/idna"
"strings"
C "github.com/Dreamacro/clash/constant"
@ -9,6 +10,7 @@ import (
type Domain struct {
*Base
domain string
rawDomain string
adapter string
}
@ -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),
domain: strings.ToLower(actualDomain),
adapter: adapter,
rawDomain: domain,
}
}

View File

@ -1,6 +1,7 @@
package common
import (
"golang.org/x/net/idna"
"strings"
C "github.com/Dreamacro/clash/constant"
@ -10,6 +11,7 @@ type DomainKeyword struct {
*Base
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),
keyword: strings.ToLower(actualDomainKeyword),
adapter: adapter,
rawKeyword: keyword,
}
}

View File

@ -1,6 +1,7 @@
package common
import (
"golang.org/x/net/idna"
"strings"
C "github.com/Dreamacro/clash/constant"
@ -10,6 +11,7 @@ type DomainSuffix struct {
*Base
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),
suffix: strings.ToLower(actualDomainKeyword),
adapter: adapter,
rawSuffix: suffix,
}
}

View File

@ -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 {