forked from mirror/gin
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
5ab90b59b0
|
@ -481,6 +481,21 @@ func TestRouterNotFound(t *testing.T) {
|
||||||
router.GET("/a", func(c *Context) {})
|
router.GET("/a", func(c *Context) {})
|
||||||
w = performRequest(router, http.MethodGet, "/")
|
w = performRequest(router, http.MethodGet, "/")
|
||||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||||
|
|
||||||
|
// Reproduction test for the bug of issue #2843
|
||||||
|
router = New()
|
||||||
|
router.NoRoute(func(c *Context) {
|
||||||
|
if c.Request.RequestURI == "/login" {
|
||||||
|
c.String(200, "login")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
router.GET("/logout", func(c *Context) {
|
||||||
|
c.String(200, "logout")
|
||||||
|
})
|
||||||
|
w = performRequest(router, http.MethodGet, "/login")
|
||||||
|
assert.Equal(t, "login", w.Body.String())
|
||||||
|
w = performRequest(router, http.MethodGet, "/logout")
|
||||||
|
assert.Equal(t, "logout", w.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouterStaticFSNotFound(t *testing.T) {
|
func TestRouterStaticFSNotFound(t *testing.T) {
|
||||||
|
|
3
tree.go
3
tree.go
|
@ -634,7 +634,8 @@ walk: // Outer loop for walking the tree
|
||||||
// Nothing found. We can recommend to redirect to the same URL with an
|
// Nothing found. We can recommend to redirect to the same URL with an
|
||||||
// extra trailing slash if a leaf exists for that path
|
// extra trailing slash if a leaf exists for that path
|
||||||
value.tsr = path == "/" ||
|
value.tsr = path == "/" ||
|
||||||
(len(prefix) == len(path)+1 && n.handlers != nil)
|
(len(prefix) == len(path)+1 && prefix[len(path)] == '/' &&
|
||||||
|
path == prefix[:len(prefix)-1] && n.handlers != nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue