Skip to content

Commit bd78de0

Browse files
committed
Fix #3500 Add escape logic for header
1 parent 81ac7d5 commit bd78de0

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

gin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ func redirectTrailingSlash(c *Context) {
670670
p := req.URL.Path
671671
if prefix := path.Clean(c.Request.Header.Get("X-Forwarded-Prefix")); prefix != "." {
672672
prefix = url.QueryEscape(prefix)
673+
prefix = strings.ReplaceAll(prefix, ".", "")
673674
prefix = strings.ReplaceAll(prefix, "%2F", "/")
674675

675676
p = prefix + "/" + req.URL.Path

routes_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ func TestRouteRedirectTrailingSlash(t *testing.T) {
186186
assert.Equal(t, 200, w.Code)
187187

188188
w = PerformRequest(router, http.MethodGet, "/path/", header{Key: "X-Forwarded-Prefix", Value: "../../bug#?"})
189-
assert.Equal(t, "../../../bug%2523%253F/path", w.Header().Get("Location"))
189+
assert.Equal(t, "//bug%2523%253F//path", w.Header().Get("Location"))
190190
assert.Equal(t, 301, w.Code)
191191

192192
w = PerformRequest(router, http.MethodGet, "/path/", header{Key: "X-Forwarded-Prefix", Value: "https://gin-gonic.com/#"})
193-
assert.Equal(t, "https%3A/gin-gonic.com/%23/https%253A/gin-gonic.com/%2523/path", w.Header().Get("Location"))
193+
assert.Equal(t, "https%3A/gin-goniccom/%23/https%253A/gin-goniccom/%2523/path", w.Header().Get("Location"))
194194
assert.Equal(t, 301, w.Code)
195195

196196
w = PerformRequest(router, http.MethodGet, "/path/", header{Key: "X-Forwarded-Prefix", Value: "#bug"})

0 commit comments

Comments
 (0)