Skip to content

Commit 1659348

Browse files
kaeyvishr
authored andcommitted
backport fix for #623 from v3 (#709)
1 parent 49c099c commit 1659348

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

group.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ func (g *Group) Use(m ...Middleware) {
1212
for _, h := range m {
1313
g.echo.middleware = append(g.echo.middleware, wrapMiddleware(h))
1414
}
15+
16+
g.echo.Any(g.echo.prefix+"*", notFoundHandler)
1517
}
1618

1719
// Connect implements the echo.Connect interface for subroutes within the Group.

router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
344344
// Static node
345345
if c = cn.findChild(search[0], skind); c != nil {
346346
// Save next
347-
if cn.label == '/' {
347+
if cn.prefix[len(cn.prefix)-1] == '/' {
348348
nk = pkind
349349
nn = cn
350350
ns = search
@@ -362,7 +362,7 @@ func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo
362362
}
363363

364364
// Save next
365-
if cn.label == '/' {
365+
if cn.prefix[len(cn.prefix)-1] == '/' {
366366
nk = akind
367367
nn = cn
368368
ns = search

router_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,37 @@ func TestRouterParamNames(t *testing.T) {
606606
assert.Equal(t, "1", c.P(1))
607607
}
608608

609+
func TestRouterStaticDynamicConflict(t *testing.T) {
610+
e := New()
611+
r := e.router
612+
c := NewContext(nil, nil, e)
613+
614+
r.Add(GET, "/dictionary/skills", func(c *Context) error {
615+
c.Set("a", 1)
616+
return nil
617+
}, e)
618+
r.Add(GET, "/dictionary/:name", func(c *Context) error {
619+
c.Set("b", 2)
620+
return nil
621+
}, e)
622+
r.Add(GET, "/server", func(c *Context) error {
623+
c.Set("c", 3)
624+
return nil
625+
}, e)
626+
627+
h, _ := r.Find(GET, "/dictionary/skills", c)
628+
h(c)
629+
assert.Equal(t, 1, c.Get("a"))
630+
c = NewContext(nil, nil, e)
631+
h, _ = r.Find(GET, "/dictionary/type", c)
632+
h(c)
633+
assert.Equal(t, 2, c.Get("b"))
634+
c = NewContext(nil, nil, e)
635+
h, _ = r.Find(GET, "/server", c)
636+
h(c)
637+
assert.Equal(t, 3, c.Get("c"))
638+
}
639+
609640
func TestRouterAPI(t *testing.T) {
610641
e := New()
611642
r := e.router

0 commit comments

Comments
 (0)