1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-12 01:22:21 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-09-16 19:28:09 -07:00
parent eef1574969
commit 853e650ee2
2 changed files with 23 additions and 9 deletions

View File

@ -347,12 +347,13 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
}
if search == "" {
// TODO: Needs improvement
if cn.findChildWithType(mtype) == nil {
continue
if cn.handler == nil {
// Look up for match-any, might have an empty value for *, e.g.
// serving a directory. Issue #207
cn = cn.findChildWithType(mtype)
ctx.pvalues[len(ctx.pvalues)-1] = ""
}
// Empty value
goto MatchAny
continue
}
// Static node
@ -390,7 +391,7 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
// Match-any node
MatchAny:
// c = cn.getChild()
// c = cn.getChild()
c = cn.findChildWithType(mtype)
if c != nil {
cn = c

View File

@ -321,19 +321,32 @@ func TestRouterTwoParam(t *testing.T) {
func TestRouterMatchAny(t *testing.T) {
e := New()
r := e.router
// Routes
r.Add(GET, "/", func(*Context) error {
return nil
}, e)
r.Add(GET, "/*", func(*Context) error {
return nil
}, e)
r.Add(GET, "/users/*", func(*Context) error {
return nil
}, e)
c := NewContext(nil, nil, e)
h, _ := r.Find(GET, "/users/", c)
h, _ := r.Find(GET, "/", c)
if assert.NotNil(t, h) {
assert.Equal(t, "", c.P(0))
}
h, _ = r.Find(GET, "/users/1", c)
h, _ = r.Find(GET, "/download", c)
if assert.NotNil(t, h) {
assert.Equal(t, "1", c.P(0))
assert.Equal(t, "download", c.P(0))
}
h, _ = r.Find(GET, "/users/joe", c)
if assert.NotNil(t, h) {
assert.Equal(t, "joe", c.P(0))
}
}