From bf6728e53b27934b1d7dbabb5f53c4078815a244 Mon Sep 17 00:00:00 2001 From: jimchen Date: Tue, 20 Aug 2024 18:12:40 +0800 Subject: [PATCH 1/2] fix: fix URL path value still unescaped when UnescapePathValues set false Closes #4033 --- gin.go | 2 +- logger.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gin.go b/gin.go index 48cc15c9..7275fecd 100644 --- a/gin.go +++ b/gin.go @@ -645,7 +645,7 @@ func (engine *Engine) HandleContext(c *Context) { func (engine *Engine) handleHTTPRequest(c *Context) { httpMethod := c.Request.Method - rPath := c.Request.URL.Path + rPath := c.Request.URL.EscapedPath() unescape := false if engine.UseRawPath && len(c.Request.URL.RawPath) > 0 { rPath = c.Request.URL.RawPath diff --git a/logger.go b/logger.go index db2c6832..741cdf00 100644 --- a/logger.go +++ b/logger.go @@ -242,7 +242,7 @@ func LoggerWithConfig(conf LoggerConfig) HandlerFunc { return func(c *Context) { // Start timer start := time.Now() - path := c.Request.URL.Path + path := c.Request.URL.EscapedPath() raw := c.Request.URL.RawQuery // Process request From 6c7a318468ce708b91c1afbf4a32e493d65fab22 Mon Sep 17 00:00:00 2001 From: jimchen Date: Wed, 21 Aug 2024 09:45:05 +0800 Subject: [PATCH 2/2] fix: fix URL path value still unescaped when UnescapePathValues set false --- gin.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gin.go b/gin.go index 7275fecd..c0b8bf34 100644 --- a/gin.go +++ b/gin.go @@ -645,10 +645,10 @@ func (engine *Engine) HandleContext(c *Context) { func (engine *Engine) handleHTTPRequest(c *Context) { httpMethod := c.Request.Method - rPath := c.Request.URL.EscapedPath() + rPath := c.Request.URL.Path unescape := false - if engine.UseRawPath && len(c.Request.URL.RawPath) > 0 { - rPath = c.Request.URL.RawPath + if engine.UseRawPath { + rPath = c.Request.URL.EscapedPath() unescape = engine.UnescapePathValues }