diff --git a/component/domain-trie/tire.go b/component/domain-trie/tire.go index 26062fc2..f4e87ff5 100644 --- a/component/domain-trie/tire.go +++ b/component/domain-trie/tire.go @@ -22,7 +22,7 @@ type Trie struct { } func isValidDomain(domain string) bool { - return domain[0] != '.' && domain[len(domain)-1] != '.' + return domain != "" && domain[0] != '.' && domain[len(domain)-1] != '.' } // Insert adds a node to the trie. diff --git a/component/domain-trie/trie_test.go b/component/domain-trie/trie_test.go index 5303596b..228106cd 100644 --- a/component/domain-trie/trie_test.go +++ b/component/domain-trie/trie_test.go @@ -26,6 +26,10 @@ func TestTrie_Basic(t *testing.T) { if !node.Data.(net.IP).Equal(localIP) { t.Error("should equal 127.0.0.1") } + + if tree.Insert("", localIP) == nil { + t.Error("should return error") + } } func TestTrie_Wildcard(t *testing.T) {