From 0c933643e2361c1b246522d30c18240c26a4ccf1 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 19 Dec 2014 15:33:51 +0800 Subject: [PATCH] improve the empty router --- tree.go | 3 +++ tree_test.go | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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 []") }