8000 Unexpected c.Param() results when UseRawPath and UnescapePathValues are true · Issue #2633 · gin-gonic/gin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Unexpected c.Param() results when UseRawPath and UnescapePathValues are true #2633
Open
@nozhT

Description

@nozhT

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

if v, err := url.QueryUnescape(val); err == nil {
to url.PathUnescape might fix the problem.

How to reproduce

package main

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

func main() {
	r := gin.New()
	r.UseRawPath = true
	r.GET("/:name/hi", func(c *gin.Context) {
		c.String(200, "Hello %s", c.Param("name"))
	})
	r.Run(":9000")
}

Expectations

$ curl 'http://localhost:9000/a+file.txt/hi' 
Hello a+file.txt
$ curl 'http://localhost:9000/a+%2Ffile.txt/hi'
Hello a+/file.txt

Actual result

$ curl 'http://localhost:9000/a+file.txt/hi' 
Hello a+file.txt
$ curl 'http://localhost:9000/a+%2Ffile.txt/hi'
Hello a /file.txt

Environment

  • go version: go1.15.2
  • gin version (or commit ref): gin v1.6.3
  • operating system: linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0