diff --git a/tree.go b/tree.go index 25947442..93e87470 100644 --- a/tree.go +++ b/tree.go @@ -422,6 +422,9 @@ func (leaf *leafInfo) match(wildcardValues []string) (ok bool, params map[string // "/admin/" -> ["admin"] // "/admin/users" -> ["admin", "users"] func splitPath(key string) []string { + if key == "" { + return []string{} + } elements := strings.Split(key, "/") if elements[0] == "" { elements = elements[1:] diff --git a/tree_test.go b/tree_test.go index 358898e7..fa289716 100644 --- a/tree_test.go +++ b/tree_test.go @@ -149,7 +149,11 @@ func TestAddTree2(t *testing.T) { } func TestSplitPath(t *testing.T) { - a := splitPath("/") + a := splitPath("") + if len(a) != 0 { + t.Fatal("/ should retrun []") + } + a = splitPath("/") if len(a) != 0 { t.Fatal("/ should retrun []") }