fix: not match top domain
This commit is contained in:
parent
ec234ac0a8
commit
7513761540
3 changed files with 20 additions and 9 deletions
|
@ -126,6 +126,9 @@ func (t *DomainTrie[T]) Optimize() {
|
||||||
func (t *DomainTrie[T]) Foreach(print func(domain string, data T)) {
|
func (t *DomainTrie[T]) Foreach(print func(domain string, data T)) {
|
||||||
for key, data := range t.root.getChildren() {
|
for key, data := range t.root.getChildren() {
|
||||||
recursion([]string{key}, data, print)
|
recursion([]string{key}, data, print)
|
||||||
|
if data != nil && data.inited {
|
||||||
|
print(joinDomain([]string{key}), data.data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@ func TestDomainSet(t *testing.T) {
|
||||||
"www.google.com",
|
"www.google.com",
|
||||||
"test.a.net",
|
"test.a.net",
|
||||||
"test.a.oc",
|
"test.a.oc",
|
||||||
|
"Mijia Cloud",
|
||||||
|
".qq.com",
|
||||||
|
"+.cn",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, domain := range domainSet {
|
for _, domain := range domainSet {
|
||||||
|
@ -22,8 +25,13 @@ func TestDomainSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
set := tree.NewDomainSet()
|
set := tree.NewDomainSet()
|
||||||
assert.NotNil(t, set)
|
assert.NotNil(t, set)
|
||||||
|
assert.True(t, set.Has("test.cn"))
|
||||||
|
assert.True(t, set.Has("cn"))
|
||||||
|
assert.True(t, set.Has("Mijia Cloud"))
|
||||||
assert.True(t, set.Has("test.a.net"))
|
assert.True(t, set.Has("test.a.net"))
|
||||||
|
assert.True(t, set.Has("www.qq.com"))
|
||||||
assert.True(t, set.Has("google.com"))
|
assert.True(t, set.Has("google.com"))
|
||||||
|
assert.False(t, set.Has("qq.com"))
|
||||||
assert.False(t, set.Has("www.baidu.com"))
|
assert.False(t, set.Has("www.baidu.com"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue