Skip to content

Unexpected c.Param() results when UseRawPath and UnescapePathValues are true #2633

Open
@nozhT

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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