Skip to content
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

Path decoded before routing #3024

Open
otcirtan opened this issue Jan 12, 2022 · 1 comment
Open

Path decoded before routing #3024

otcirtan opened this issue Jan 12, 2022 · 1 comment

Comments

@otcirtan
Copy link

Description

It appears that the path is decoded before matching/routing, leading to erroneous matches when the URL contains %2F.

How to reproduce

package main

import (
	"github.com/gin-gonic/gin"
)

func main() {
	g := gin.Default()
	g.GET("/hello/:param1", func(c *gin.Context) {
		c.String(200, "One parameter: '%s'", c.Param("param1"))
	})
	g.GET("/hello/:param1/:param2", func(c *gin.Context) {
		c.String(200, "Two parameters: '%s' and '%s'", c.Param("param1"), c.Param("param2"))
	})
	g.Run(":9000")
}

Expectations

I expect a path component with %2F to match one path parameter:

$ curl localhost:9000/hello/p1%2Fp2
One parameter: 'p1%2Fp2'

Actual result

~> curl localhost:9000/hello/p1
One parameter: 'p1'
~> curl localhost:9000/hello/p1/p2
Two parameters: 'p1' and 'p2'
~> curl localhost:9000/hello/p1%2Fp2
Two parameters: 'p1' and 'p2'

Environment

  • go version: 1.17.5
  • gin version (or commit ref): v1.7.7
  • operating system: macOS 11.6.2 (darwin/amd64)

Related issues

I suspect that issue 2047 has the same underlying problem.

@otcirtan
Copy link
Author

otcirtan commented Jan 12, 2022

Setting engine.UseRawPath = true resolves this problem. The logging is wrong, though

$ curl localhost:9000/hello/p1%2Fp2
...
[GIN] 2022/01/12 - 00:00:00 | 200 |      14.162µs |             ::1 | GET      "/hello/p1/p2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant