From d2940af0c841e311d5ef45350c9920654a657947 Mon Sep 17 00:00:00 2001 From: Deepak kudi Date: Fri, 22 May 2026 08:56:24 +0530 Subject: [PATCH] Fix fixed path redirects with raw paths --- gin.go | 1 + routes_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/gin.go b/gin.go index 2e033bf3..8a27737b 100644 --- a/gin.go +++ b/gin.go @@ -811,6 +811,7 @@ func redirectFixedPath(c *Context, root *node, trailingSlash bool) bool { if fixedPath, ok := root.findCaseInsensitivePath(cleanPath(rPath), trailingSlash); ok { req.URL.Path = bytesconv.BytesToString(fixedPath) + req.URL.RawPath = "" redirectRequest(c) return true } diff --git a/routes_test.go b/routes_test.go index 1cae3fce..b04fb686 100644 --- a/routes_test.go +++ b/routes_test.go @@ -273,6 +273,24 @@ func TestRouteRedirectFixedPath(t *testing.T) { 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. func TestRouteParamsByName(t *testing.T) { name := ""