mirror of
https://github.com/labstack/echo.git
synced 2024-11-28 08:38:39 +02:00
parent
ae55310e59
commit
207a141d5d
16
router.go
16
router.go
@ -20,8 +20,8 @@ type (
|
|||||||
pnames []string
|
pnames []string
|
||||||
methodHandler *methodHandler
|
methodHandler *methodHandler
|
||||||
}
|
}
|
||||||
kind uint8
|
kind uint8
|
||||||
children []*node
|
children []*node
|
||||||
methodHandler struct {
|
methodHandler struct {
|
||||||
connect HandlerFunc
|
connect HandlerFunc
|
||||||
delete HandlerFunc
|
delete HandlerFunc
|
||||||
@ -218,9 +218,6 @@ func (n *node) findChildWithLabel(l byte) *node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *node) findChildByKind(t kind) *node {
|
func (n *node) findChildByKind(t kind) *node {
|
||||||
if n == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
for _, c := range n.children {
|
for _, c := range n.children {
|
||||||
if c.kind == t {
|
if c.kind == t {
|
||||||
return c
|
return c
|
||||||
@ -339,10 +336,14 @@ func (r *Router) Find(method, path string, c Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if l == pl {
|
if l == pl {
|
||||||
// Continue search
|
// Continue search
|
||||||
search = search[l:]
|
search = search[l:]
|
||||||
} else {
|
} else {
|
||||||
|
if nn == nil { // Issue #1348
|
||||||
|
return // Not found
|
||||||
|
}
|
||||||
cn = nn
|
cn = nn
|
||||||
search = ns
|
search = ns
|
||||||
if nk == pkind {
|
if nk == pkind {
|
||||||
@ -350,8 +351,6 @@ func (r *Router) Find(method, path string, c Context) {
|
|||||||
} else if nk == akind {
|
} else if nk == akind {
|
||||||
goto Any
|
goto Any
|
||||||
}
|
}
|
||||||
// Not found
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if search == "" {
|
if search == "" {
|
||||||
@ -408,8 +407,7 @@ func (r *Router) Find(method, path string, c Context) {
|
|||||||
goto Any
|
goto Any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Not found
|
return // Not found
|
||||||
return
|
|
||||||
}
|
}
|
||||||
pvalues[len(cn.pnames)-1] = search
|
pvalues[len(cn.pnames)-1] = search
|
||||||
break
|
break
|
||||||
|
@ -741,6 +741,18 @@ func TestRouterPriority(t *testing.T) {
|
|||||||
assert.Equal(t, "joe/books", c.Param("*"))
|
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
|
// Issue #372
|
||||||
func TestRouterPriorityNotFound(t *testing.T) {
|
func TestRouterPriorityNotFound(t *testing.T) {
|
||||||
e := New()
|
e := New()
|
||||||
@ -756,12 +768,6 @@ func TestRouterPriorityNotFound(t *testing.T) {
|
|||||||
c.Set("b", 2)
|
c.Set("b", 2)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
r.Add(http.MethodGet, "/:lang/", func(c Context) error {
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
r.Add(http.MethodGet, "/:lang/dupa", func(c Context) error {
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
// Find
|
// Find
|
||||||
r.Find(http.MethodGet, "/a/foo", c)
|
r.Find(http.MethodGet, "/a/foo", c)
|
||||||
|
Loading…
Reference in New Issue
Block a user