0c933643 by astaxie

improve the empty router

1 parent d3ab1579
...@@ -422,6 +422,9 @@ func (leaf *leafInfo) match(wildcardValues []string) (ok bool, params map[string ...@@ -422,6 +422,9 @@ func (leaf *leafInfo) match(wildcardValues []string) (ok bool, params map[string
422 // "/admin/" -> ["admin"] 422 // "/admin/" -> ["admin"]
423 // "/admin/users" -> ["admin", "users"] 423 // "/admin/users" -> ["admin", "users"]
424 func splitPath(key string) []string { 424 func splitPath(key string) []string {
425 if key == "" {
426 return []string{}
427 }
425 elements := strings.Split(key, "/") 428 elements := strings.Split(key, "/")
426 if elements[0] == "" { 429 if elements[0] == "" {
427 elements = elements[1:] 430 elements = elements[1:]
......
...@@ -149,7 +149,11 @@ func TestAddTree2(t *testing.T) { ...@@ -149,7 +149,11 @@ func TestAddTree2(t *testing.T) {
149 } 149 }
150 150
151 func TestSplitPath(t *testing.T) { 151 func TestSplitPath(t *testing.T) {
152 a := splitPath("/") 152 a := splitPath("")
153 if len(a) != 0 {
154 t.Fatal("/ should retrun []")
155 }
156 a = splitPath("/")
153 if len(a) != 0 { 157 if len(a) != 0 {
154 t.Fatal("/ should retrun []") 158 t.Fatal("/ should retrun []")
155 } 159 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!