chore: Introducing Punycode conversion for domain matching

This commit is contained in:
xishang0128 2024-04-01 16:21:34 +08:00
parent 56ed9019a6
commit f3743fc7f9
No known key found for this signature in database
GPG key ID: 44A1E10B5ADF68CB
3 changed files with 9 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import (
"strings"
C "github.com/metacubex/mihomo/constant"
"golang.org/x/net/idna"
)
type Domain struct {
@ -29,9 +30,10 @@ func (d *Domain) Payload() string {
}
func NewDomain(domain string, adapter string) *Domain {
punycode, _ := idna.ToASCII(strings.ToLower(domain))
return &Domain{
Base: &Base{},
domain: strings.ToLower(domain),
domain: punycode,
adapter: adapter,
}
}

View file

@ -4,6 +4,7 @@ import (
"strings"
C "github.com/metacubex/mihomo/constant"
"golang.org/x/net/idna"
)
type DomainKeyword struct {
@ -30,9 +31,10 @@ func (dk *DomainKeyword) Payload() string {
}
func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
punycode, _ := idna.ToASCII(strings.ToLower(keyword))
return &DomainKeyword{
Base: &Base{},
keyword: strings.ToLower(keyword),
keyword: punycode,
adapter: adapter,
}
}

View file

@ -4,6 +4,7 @@ import (
"strings"
C "github.com/metacubex/mihomo/constant"
"golang.org/x/net/idna"
)
type DomainSuffix struct {
@ -30,9 +31,10 @@ func (ds *DomainSuffix) Payload() string {
}
func NewDomainSuffix(suffix string, adapter string) *DomainSuffix {
punycode, _ := idna.ToASCII(strings.ToLower(suffix))
return &DomainSuffix{
Base: &Base{},
suffix: strings.ToLower(suffix),
suffix: punycode,
adapter: adapter,
}
}