diff --git a/router.go b/router.go index 8d3a01802..5592d8cc5 100644 --- a/router.go +++ b/router.go @@ -20,8 +20,8 @@ type ( pnames []string methodHandler *methodHandler } - kind uint8 - children []*node + kind uint8 + children []*node methodHandler struct { connect HandlerFunc delete HandlerFunc @@ -336,10 +336,14 @@ func (r *Router) Find(method, path string, c Context) { } } + if l == pl { // Continue search search = search[l:] } else { + if nn == nil { // Issue #1348 + return // Not found + } cn = nn search = ns if nk == pkind { @@ -347,8 +351,6 @@ func (r *Router) Find(method, path string, c Context) { } else if nk == akind { goto Any } - // Not found - return } if search == "" { @@ -405,8 +407,7 @@ func (r *Router) Find(method, path string, c Context) { goto Any } } - // Not found - return + return // Not found } pvalues[len(cn.pnames)-1] = search break diff --git a/router_test.go b/router_test.go index a5d53c0a5..66746d0b1 100644 --- a/router_test.go +++ b/router_test.go @@ -741,6 +741,18 @@ func TestRouterPriority(t *testing.T) { assert.Equal(t, "joe/books", c.Param("*")) } +func TestRouterIssue1348(t *testing.T) { + e := New() + r := e.router + + r.Add(http.MethodGet, "/:lang/", func(c Context) error { + return nil + }) + r.Add(http.MethodGet, "/:lang/dupa", func(c Context) error { + return nil + }) +} + // Issue #372 func TestRouterPriorityNotFound(t *testing.T) { e := New()