diff --git a/router.go b/router.go index 42a05663..b447a2ad 100644 --- a/router.go +++ b/router.go @@ -379,6 +379,10 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo // c = cn.getChild() if cn = cn.findChildByKind(mkind); cn == nil { // Not found + if nn != nil { // Issue #217 + cn = nn + continue + } return } ctx.pvalues[len(cn.pnames)-1] = search diff --git a/router_test.go b/router_test.go index c3357223..7876e9cf 100644 --- a/router_test.go +++ b/router_test.go @@ -503,6 +503,48 @@ func TestRouterPriority(t *testing.T) { } } +// Issue #217 +func TestRouterPriorityWithMatchAny(t *testing.T) { + e := New() + r := e.router + + // Routes + r.Add(GET, "/aa", func(c *Context) error { + c.Set("a", 1) + return nil + }, e) + r.Add(GET, "/ab", func(c *Context) error { + c.Set("b", 2) + return nil + }, e) + r.Add(GET, "/*", func(c *Context) error { + c.Set("c", 3) + return nil + }, e) + c := NewContext(nil, nil, e) + + // Route > /aa + h, _ := r.Find(GET, "/aa", c) + if assert.NotNil(t, h) { + h(c) + assert.Equal(t, 1, c.Get("a")) + } + + // Route > /ab + h, _ = r.Find(GET, "/ab", c) + if assert.NotNil(t, h) { + h(c) + assert.Equal(t, 2, c.Get("b")) + } + + // Route > /* + h, _ = r.Find(GET, "/abc", c) + if assert.NotNil(t, h) { + h(c) + assert.Equal(t, 3, c.Get("c")) + } +} + func TestRouterParamNames(t *testing.T) { e := New() r := e.router