fix: IDNA domain match
This commit is contained in:
parent
bf55428954
commit
c1a99b9be4
4 changed files with 33 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"golang.org/x/net/idna"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
|
@ -8,8 +9,9 @@ import (
|
||||||
|
|
||||||
type Domain struct {
|
type Domain struct {
|
||||||
*Base
|
*Base
|
||||||
domain string
|
domain string
|
||||||
adapter string
|
rawDomain string
|
||||||
|
adapter string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Domain) RuleType() C.RuleType {
|
func (d *Domain) RuleType() C.RuleType {
|
||||||
|
@ -28,14 +30,16 @@ func (d *Domain) Adapter() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Domain) Payload() string {
|
func (d *Domain) Payload() string {
|
||||||
return d.domain
|
return d.rawDomain
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDomain(domain string, adapter string) *Domain {
|
func NewDomain(domain string, adapter string) *Domain {
|
||||||
|
actualDomain, _ := idna.ToASCII(domain)
|
||||||
return &Domain{
|
return &Domain{
|
||||||
Base: &Base{},
|
Base: &Base{},
|
||||||
domain: strings.ToLower(domain),
|
domain: strings.ToLower(actualDomain),
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
|
rawDomain: domain,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"golang.org/x/net/idna"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
|
@ -8,8 +9,9 @@ import (
|
||||||
|
|
||||||
type DomainKeyword struct {
|
type DomainKeyword struct {
|
||||||
*Base
|
*Base
|
||||||
keyword string
|
keyword string
|
||||||
adapter string
|
adapter string
|
||||||
|
rawKeyword string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dk *DomainKeyword) RuleType() C.RuleType {
|
func (dk *DomainKeyword) RuleType() C.RuleType {
|
||||||
|
@ -29,14 +31,16 @@ func (dk *DomainKeyword) Adapter() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dk *DomainKeyword) Payload() string {
|
func (dk *DomainKeyword) Payload() string {
|
||||||
return dk.keyword
|
return dk.rawKeyword
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
|
func NewDomainKeyword(keyword string, adapter string) *DomainKeyword {
|
||||||
|
actualDomainKeyword, _ := idna.ToASCII(keyword)
|
||||||
return &DomainKeyword{
|
return &DomainKeyword{
|
||||||
Base: &Base{},
|
Base: &Base{},
|
||||||
keyword: strings.ToLower(keyword),
|
keyword: strings.ToLower(actualDomainKeyword),
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
|
rawKeyword: keyword,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"golang.org/x/net/idna"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
|
@ -8,8 +9,9 @@ import (
|
||||||
|
|
||||||
type DomainSuffix struct {
|
type DomainSuffix struct {
|
||||||
*Base
|
*Base
|
||||||
suffix string
|
suffix string
|
||||||
adapter string
|
adapter string
|
||||||
|
rawSuffix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DomainSuffix) RuleType() C.RuleType {
|
func (ds *DomainSuffix) RuleType() C.RuleType {
|
||||||
|
@ -29,14 +31,16 @@ func (ds *DomainSuffix) Adapter() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *DomainSuffix) Payload() string {
|
func (ds *DomainSuffix) Payload() string {
|
||||||
return ds.suffix
|
return ds.rawSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDomainSuffix(suffix string, adapter string) *DomainSuffix {
|
func NewDomainSuffix(suffix string, adapter string) *DomainSuffix {
|
||||||
|
actualDomainKeyword, _ := idna.ToASCII(suffix)
|
||||||
return &DomainSuffix{
|
return &DomainSuffix{
|
||||||
Base: &Base{},
|
Base: &Base{},
|
||||||
suffix: strings.ToLower(suffix),
|
suffix: strings.ToLower(actualDomainKeyword),
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
|
rawSuffix: suffix,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/Dreamacro/clash/component/trie"
|
"github.com/Dreamacro/clash/component/trie"
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"github.com/Dreamacro/clash/log"
|
"github.com/Dreamacro/clash/log"
|
||||||
|
"golang.org/x/net/idna"
|
||||||
)
|
)
|
||||||
|
|
||||||
type domainStrategy struct {
|
type domainStrategy struct {
|
||||||
|
@ -27,7 +28,8 @@ func (d *domainStrategy) OnUpdate(rules []string) {
|
||||||
domainTrie := trie.New[bool]()
|
domainTrie := trie.New[bool]()
|
||||||
count := 0
|
count := 0
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
err := domainTrie.Insert(rule, true)
|
actualDomain, _ := idna.ToASCII(rule)
|
||||||
|
err := domainTrie.Insert(actualDomain, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnln("invalid domain:[%s]", rule)
|
log.Warnln("invalid domain:[%s]", rule)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue