Skip to content

Commit

Permalink
chore: Introducing Punycode conversion for domain matching
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Apr 1, 2024
1 parent 56ed901 commit f3743fc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion rules/common/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

C "github.com/metacubex/mihomo/constant"
"golang.org/x/net/idna"
)

type Domain struct {
Expand All @@ -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,
}
}
Expand Down
4 changes: 3 additions & 1 deletion rules/common/domain_keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

C "github.com/metacubex/mihomo/constant"
"golang.org/x/net/idna"
)

type DomainKeyword struct {
Expand All @@ -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,
}
}
Expand Down
4 changes: 3 additions & 1 deletion rules/common/domain_suffix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

C "github.com/metacubex/mihomo/constant"
"golang.org/x/net/idna"
)

type DomainSuffix struct {
Expand All @@ -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,
}
}
Expand Down

0 comments on commit f3743fc

Please sign in to comment.