mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 14:49:27 +08:00
Merge 4b97508f7343b39c88d696f524feb3b52a31789e into dcaa4296d111981ffb31ac3eba90bb63e1eb5ab9
This commit is contained in:
commit
e582eb1f5f
1
gin.go
1
gin.go
@ -811,6 +811,7 @@ func redirectFixedPath(c *Context, root *node, trailingSlash bool) bool {
|
|||||||
|
|
||||||
if fixedPath, ok := root.findCaseInsensitivePath(cleanPath(rPath), trailingSlash); ok {
|
if fixedPath, ok := root.findCaseInsensitivePath(cleanPath(rPath), trailingSlash); ok {
|
||||||
req.URL.Path = bytesconv.BytesToString(fixedPath)
|
req.URL.Path = bytesconv.BytesToString(fixedPath)
|
||||||
|
req.URL.RawPath = ""
|
||||||
redirectRequest(c)
|
redirectRequest(c)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -273,6 +273,24 @@ func TestRouteRedirectFixedPath(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRouteRedirectFixedPathWithRawPath(t *testing.T) {
|
||||||
|
router := New()
|
||||||
|
router.RedirectFixedPath = true
|
||||||
|
router.RedirectTrailingSlash = false
|
||||||
|
router.UseRawPath = true
|
||||||
|
router.UnescapePathValues = false
|
||||||
|
|
||||||
|
router.GET("/あ", func(c *Context) {})
|
||||||
|
|
||||||
|
w := PerformRequest(router, http.MethodGet, "/%e3%81%82")
|
||||||
|
assert.Equal(t, "/%E3%81%82", w.Header().Get("Location"))
|
||||||
|
assert.Equal(t, http.StatusMovedPermanently, w.Code)
|
||||||
|
|
||||||
|
w = PerformRequest(router, http.MethodGet, "/%E3%81%82")
|
||||||
|
assert.Empty(t, w.Header().Get("Location"))
|
||||||
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
|
}
|
||||||
|
|
||||||
// TestContextParamsGet tests that a parameter can be parsed from the URL.
|
// TestContextParamsGet tests that a parameter can be parsed from the URL.
|
||||||
func TestRouteParamsByName(t *testing.T) {
|
func TestRouteParamsByName(t *testing.T) {
|
||||||
name := ""
|
name := ""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user