From c2c69525c13741dcec582dc52f7ef59b1721859d Mon Sep 17 00:00:00 2001 From: t0rchwo0d Date: Fri, 17 Feb 2023 12:14:03 +0900 Subject: [PATCH] Revert "Add escape logic for header (#3500)" This reverts commit 81ac7d55a09e34013225db0aeac6e70c1ae68928. --- gin.go | 4 ---- routes_test.go | 12 ------------ 2 files changed, 16 deletions(-) diff --git a/gin.go b/gin.go index 32dae2497f..35159d03fa 100644 --- a/gin.go +++ b/gin.go @@ -9,7 +9,6 @@ import ( "html/template" "net" "net/http" - "net/url" "os" "path" "strings" @@ -669,9 +668,6 @@ func redirectTrailingSlash(c *Context) { req := c.Request p := req.URL.Path if prefix := path.Clean(c.Request.Header.Get("X-Forwarded-Prefix")); prefix != "." { - prefix = url.QueryEscape(prefix) - prefix = strings.ReplaceAll(prefix, "%2F", "/") - p = prefix + "/" + req.URL.Path } req.URL.Path = p + "/" diff --git a/routes_test.go b/routes_test.go index 5310caec25..ada8e1e457 100644 --- a/routes_test.go +++ b/routes_test.go @@ -185,18 +185,6 @@ func TestRouteRedirectTrailingSlash(t *testing.T) { w = PerformRequest(router, http.MethodGet, "/path2/", header{Key: "X-Forwarded-Prefix", Value: "/api/"}) assert.Equal(t, 200, w.Code) - w = PerformRequest(router, http.MethodGet, "/path/", header{Key: "X-Forwarded-Prefix", Value: "../../bug#?"}) - assert.Equal(t, "../../../bug%2523%253F/path", w.Header().Get("Location")) - assert.Equal(t, 301, w.Code) - - w = PerformRequest(router, http.MethodGet, "/path/", header{Key: "X-Forwarded-Prefix", Value: "https://gin-gonic.com/#"}) - assert.Equal(t, "https%3A/gin-gonic.com/%23/https%253A/gin-gonic.com/%2523/path", w.Header().Get("Location")) - assert.Equal(t, 301, w.Code) - - w = PerformRequest(router, http.MethodGet, "/path/", header{Key: "X-Forwarded-Prefix", Value: "#bug"}) - assert.Equal(t, "%23bug/%2523bug/path", w.Header().Get("Location")) - assert.Equal(t, 301, w.Code) - router.RedirectTrailingSlash = false w = PerformRequest(router, http.MethodGet, "/path/")