1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-20 19:52:47 +02:00

backport fix for #623 from v3 (#709)

This commit is contained in:
Konstantin Kulikov 2016-11-03 20:41:43 +03:00 committed by Vishal Rana
parent 49c099c3b3
commit 1659348a67
3 changed files with 35 additions and 2 deletions

View File

@ -12,6 +12,8 @@ func (g *Group) Use(m ...Middleware) {
for _, h := range m {
g.echo.middleware = append(g.echo.middleware, wrapMiddleware(h))
}
g.echo.Any(g.echo.prefix+"*", notFoundHandler)
}
// Connect implements the echo.Connect interface for subroutes within the Group.

View File

@ -344,7 +344,7 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
// Static node
if c = cn.findChild(search[0], skind); c != nil {
// Save next
if cn.label == '/' {
if cn.prefix[len(cn.prefix)-1] == '/' {
nk = pkind
nn = cn
ns = search
@ -362,7 +362,7 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
}
// Save next
if cn.label == '/' {
if cn.prefix[len(cn.prefix)-1] == '/' {
nk = akind
nn = cn
ns = search

View File

@ -606,6 +606,37 @@ func TestRouterParamNames(t *testing.T) {
assert.Equal(t, "1", c.P(1))
}
func TestRouterStaticDynamicConflict(t *testing.T) {
e := New()
r := e.router
c := NewContext(nil, nil, e)
r.Add(GET, "/dictionary/skills", func(c *Context) error {
c.Set("a", 1)
return nil
}, e)
r.Add(GET, "/dictionary/:name", func(c *Context) error {
c.Set("b", 2)
return nil
}, e)
r.Add(GET, "/server", func(c *Context) error {
c.Set("c", 3)
return nil
}, e)
h, _ := r.Find(GET, "/dictionary/skills", c)
h(c)
assert.Equal(t, 1, c.Get("a"))
c = NewContext(nil, nil, e)
h, _ = r.Find(GET, "/dictionary/type", c)
h(c)
assert.Equal(t, 2, c.Get("b"))
c = NewContext(nil, nil, e)
h, _ = r.Find(GET, "/server", c)
h(c)
assert.Equal(t, 3, c.Get("c"))
}
func TestRouterAPI(t *testing.T) {
e := New()
r := e.router