mirror of https://github.com/Dreamacro/clash.git
Fix: domain wildcard behavior
This commit is contained in:
parent
8eddcd77bf
commit
3fc6d55003
|
@ -81,6 +81,7 @@ func (t *Trie) Search(domain string) *Node {
|
|||
|
||||
n := t.root
|
||||
var dotWildcardNode *Node
|
||||
var wildcardNode *Node
|
||||
for i := len(parts) - 1; i >= 0; i-- {
|
||||
part := parts[i]
|
||||
|
||||
|
@ -88,10 +89,16 @@ func (t *Trie) Search(domain string) *Node {
|
|||
dotWildcardNode = node
|
||||
}
|
||||
|
||||
if n.hasChild(part) {
|
||||
n = n.getChild(part)
|
||||
} else {
|
||||
n = n.getChild(wildcard)
|
||||
child := n.getChild(part)
|
||||
if child == nil && wildcardNode != nil {
|
||||
child = wildcardNode.getChild(part)
|
||||
}
|
||||
wildcardNode = n.getChild(wildcard)
|
||||
|
||||
n = child
|
||||
if n == nil {
|
||||
n = wildcardNode
|
||||
wildcardNode = nil
|
||||
}
|
||||
|
||||
if n == nil {
|
||||
|
|
|
@ -34,6 +34,7 @@ func TestTrie_Wildcard(t *testing.T) {
|
|||
"*.dev",
|
||||
".org",
|
||||
".example.net",
|
||||
".apple.*",
|
||||
}
|
||||
|
||||
for _, domain := range domains {
|
||||
|
@ -44,6 +45,7 @@ func TestTrie_Wildcard(t *testing.T) {
|
|||
assert.NotNil(t, tree.Search("sub.foo.example.com"))
|
||||
assert.NotNil(t, tree.Search("test.org"))
|
||||
assert.NotNil(t, tree.Search("test.example.net"))
|
||||
assert.NotNil(t, tree.Search("test.apple.com"))
|
||||
assert.Nil(t, tree.Search("foo.sub.example.com"))
|
||||
assert.Nil(t, tree.Search("foo.example.dev"))
|
||||
assert.Nil(t, tree.Search("example.com"))
|
||||
|
|
Loading…
Reference in New Issue