From 1b70cbebbea10b1684c752d995786923c936e77b Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Wed, 14 Jun 2017 16:30:53 -0700 Subject: [PATCH] Fixed #954 Signed-off-by: Vishal Rana --- .gitignore | 2 ++ router.go | 2 +- router_test.go | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3fdd669d..861c7230 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ coverage.txt _test vendor +.idea +*.iml diff --git a/router.go b/router.go index 2ef904e0..626fe225 100644 --- a/router.go +++ b/router.go @@ -394,7 +394,7 @@ func (r *Router) Find(method, path string, c Context) { if cn = cn.findChildByKind(akind); cn == nil { if nn != nil { cn = nn - nn = nil // Next + nn = cn.parent // Next (Issue #954) search = ns if nk == pkind { goto Param diff --git a/router_test.go b/router_test.go index ee48f951..1af1ee5c 100644 --- a/router_test.go +++ b/router_test.go @@ -584,6 +584,33 @@ func TestRouterMatchAny(t *testing.T) { assert.Equal(t, "joe", c.Param("*")) } +func TestRouterMatchAnyMultiLevel(t *testing.T) { + e := New() + r := e.router + handler := func(c Context) error { + c.Set("path", c.Path()) + return nil + } + + // Routes + r.Add(GET, "/api/users/jack", handler) + r.Add(GET, "/api/users/jill", handler) + r.Add(GET, "/*", handler) + + c := e.NewContext(nil, nil).(*context) + r.Find(GET, "/api/users/jack", c) + c.handler(c) + assert.Equal(t, "/api/users/jack", c.Get("path")) + + r.Find(GET, "/api/users/jill", c) + c.handler(c) + assert.Equal(t, "/api/users/jill", c.Get("path")) + + r.Find(GET, "/api/users/joe", c) + c.handler(c) + assert.Equal(t, "/*", c.Get("path")) +} + func TestRouterMicroParam(t *testing.T) { e := New() r := e.router