Skip to content

Can't unescape multi byte path parameters #1117

Description

@lon9

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
/ / / / / / / / / / / / / / / / / /

Please use forum https://forum.labstack.com to ask questions!

/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
/ / / / / / / / / / / / / / / / / /

Issue Description

c.Params can't unescape when the parameter is a small case percent encoded string like %e3%81%93%e3%82%93%e3%81%ab%e3%81%a1%e3%82%8f
but it can unescape a big case like %E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%82%8F

With default template engine in Go escapes multi byte in href to small case percent encoded string automatically, so we can't get unescaped string.

The cause is here.
In the case of a small case, r.RawPath becomes /%e3%81%93%e3%82%93%e3%81%ab%e3%81%a1%e3%82%8f so we get a escaped parameter. but in the case of a big case, r.RawPath becomes empty so we get a unescaped parameter from r.Path
Example playground

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

We can get a unescaped path parameter.

Actual behaviour

We can get a escaped path parameter.

Steps to reproduce

Passing small case percent encoded string as path parameter.

Working code to debug

package main

import (
	"net/http"

	"github.com/labstack/echo"
)

func main() {
	e := echo.New()
	e.GET("/:tag", func(c echo.Context) error {
		return c.String(http.StatusOK, c.Param("tag"))
	})
	e.Logger.Fatal(e.Start(":1323"))
}

Access to localhost:1312/%e3%81%93%e3%82%93%e3%81%ab%e3%81%a1%e3%82%8f and localhost:1323/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%82%8F
then we can get different responses %e3%81%93%e3%82%93%e3%81%ab%e3%81%a1%e3%82%8f and こんにちわ

Version/commit

f867058

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions