-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected c.Param() results when UseRawPath and UnescapePathValues are true #2633
Comments
Here's a workaround that uses a middleware to manually unescape the path params using app.UseRawPath = true
app.UnescapePathValues = false
app.Use(func(c *gin.Context) {
for idx, param := range c.Params {
unescaped, err := url.PathUnescape(param.Value)
if err == nil {
param.Value = unescaped
c.Params[idx] = param
}
}
c.Next()
}) |
Just found out this incorrectly decodes I think it's because Line 396 in a573ec6
uses URL.RawPath only if it exists instead of use URL.EscapedPath .
|
I would like to bring attention to this issue, since it is still present and essentially doesn't allow for raw path use. The root is in the fact that Go's
I am not sure, whether it is a good idea on its own, but that's what it is. However, I would love to see Gin working around this (annoying) issue. |
Description
'+' plus signs in path parameters are unescaped to ' ' (the space character) when UnescapePathValues and UseRawPath are set to true.
However this problem does not appear if the URL path segment does not contain %2F (URLencoded '/').
Changing
gin/tree.go
Line 446 in a573ec6
url.PathUnescape
might fix the problem.How to reproduce
Expectations
Actual result
Environment
The text was updated successfully, but these errors were encountered: