Fix(domain-trie): crash when insert
This commit is contained in:
parent
09917a2a95
commit
3dd9ea52d8
2 changed files with 5 additions and 1 deletions
|
@ -22,7 +22,7 @@ type Trie struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isValidDomain(domain string) bool {
|
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.
|
// Insert adds a node to the trie.
|
||||||
|
|
|
@ -26,6 +26,10 @@ func TestTrie_Basic(t *testing.T) {
|
||||||
if !node.Data.(net.IP).Equal(localIP) {
|
if !node.Data.(net.IP).Equal(localIP) {
|
||||||
t.Error("should equal 127.0.0.1")
|
t.Error("should equal 127.0.0.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tree.Insert("", localIP) == nil {
|
||||||
|
t.Error("should return error")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrie_Wildcard(t *testing.T) {
|
func TestTrie_Wildcard(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue