Преглед изворни кода

check init state of DomainMatcherGroup. fixes #1238

Darien Raymond пре 7 година
родитељ
комит
899b1399ee
2 измењених фајлова са 12 додато и 0 уклоњено
  1. 4 0
      common/strmatcher/domain_matcher.go
  2. 8 0
      common/strmatcher/domain_matcher_test.go

+ 4 - 0
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]

+ 8 - 0
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)
+	}
+}