diff --git a/common/strmatcher/domain_matcher.go b/common/strmatcher/domain_matcher.go index d31dbf724..46a755d3a 100644 --- a/common/strmatcher/domain_matcher.go +++ b/common/strmatcher/domain_matcher.go @@ -39,6 +39,10 @@ func (g *DomainMatcherGroup) Add(domain string, value uint32) { func (g *DomainMatcherGroup) Match(domain string) uint32 { current := g.root + if current == nil { + return 0 + } + parts := breakDomain(domain) for i := len(parts) - 1; i >= 0; i-- { part := parts[i] diff --git a/common/strmatcher/domain_matcher_test.go b/common/strmatcher/domain_matcher_test.go index 54a81d9b8..f8f0b42a1 100644 --- a/common/strmatcher/domain_matcher_test.go +++ b/common/strmatcher/domain_matcher_test.go @@ -33,3 +33,11 @@ func TestDomainMatcherGroup(t *testing.T) { } } } + +func TestEmptyDomainMatcherGroup(t *testing.T) { + g := new(DomainMatcherGroup) + r := g.Match("v2ray.com") + if r != 0 { + t.Error("Expect 0, but ", r) + } +}