mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-13 00:59:29 +08:00
Compare commits
4 Commits
fae4bcaa1a
...
dc2c7e91e6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc2c7e91e6 | ||
|
|
b7dd5120ef | ||
|
|
29db90e1fc | ||
|
|
6c8ec4deda |
1
gin.go
1
gin.go
@ -788,6 +788,7 @@ func redirectTrailingSlash(c *Context) {
|
||||
p = prefix + "/" + req.URL.Path
|
||||
}
|
||||
req.URL.Path = p + "/"
|
||||
p = regexp.MustCompile("^/{2,}").ReplaceAllString(p, "/")
|
||||
if length := len(p); length > 1 && p[length-1] == '/' {
|
||||
req.URL.Path = p[:length-1]
|
||||
}
|
||||
|
||||
@ -150,8 +150,13 @@ func TestRouteRedirectTrailingSlash(t *testing.T) {
|
||||
router.GET("/path2/", func(c *Context) {})
|
||||
router.POST("/path3", func(c *Context) {})
|
||||
router.PUT("/path4/", func(c *Context) {})
|
||||
router.GET("/:param1/:param2", func(c *Context) {})
|
||||
|
||||
w := PerformRequest(router, http.MethodGet, "/path/")
|
||||
w := PerformRequest(router, http.MethodGet, "//path/")
|
||||
assert.Equal(t, "/path", w.Header().Get("Location"))
|
||||
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
||||
|
||||
w = PerformRequest(router, http.MethodGet, "/path/")
|
||||
assert.Equal(t, "/path", w.Header().Get("Location"))
|
||||
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user