1
0
mirror of https://github.com/labstack/echo.git synced 2025-03-17 21:08:05 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-02-21 21:45:11 -08:00
parent 6914162d64
commit c782b3fc75
2 changed files with 46 additions and 0 deletions

View File

@ -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

View File

@ -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