mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
commit
65561a5461
13
router.go
13
router.go
@ -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
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user