From dc0f2d73274fb0e722b169dc3275479c7e19555d Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Wed, 7 Jun 2017 08:55:40 -0700 Subject: [PATCH] Fixed url.PathUnescape for go1.7 Signed-off-by: Vishal Rana --- echo.go | 3 +-- middleware/static.go | 3 +-- util_go17.go | 12 ++++++++++++ util_go18.go | 10 ++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 util_go17.go create mode 100644 util_go18.go diff --git a/echo.go b/echo.go index 08d9a231..cfd96ea1 100644 --- a/echo.go +++ b/echo.go @@ -45,7 +45,6 @@ import ( stdLog "log" "net" "net/http" - "net/url" "path" "path/filepath" "reflect" @@ -435,7 +434,7 @@ func (e *Echo) Static(prefix, root string) { func static(i i, prefix, root string) { h := func(c Context) error { - p, err := url.PathUnescape(c.Param("*")) + p, err := PathUnescape(c.Param("*")) if err != nil { return err } diff --git a/middleware/static.go b/middleware/static.go index f992773a..5e7808d1 100644 --- a/middleware/static.go +++ b/middleware/static.go @@ -2,7 +2,6 @@ package middleware import ( "fmt" - "net/url" "os" "path" "path/filepath" @@ -76,7 +75,7 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc { if strings.HasSuffix(c.Path(), "*") { // When serving from a group, e.g. `/static*`. p = c.Param("*") } - p, err = url.PathUnescape(p) + p, err = echo.PathUnescape(p) if err != nil { return err } diff --git a/util_go17.go b/util_go17.go new file mode 100644 index 00000000..6b5d6b09 --- /dev/null +++ b/util_go17.go @@ -0,0 +1,12 @@ +// +build go1.7,!go1.8 + +package echo + +import ( + "net/url" +) + +// PathUnescape is wraps `url.QueryUnescape` +func PathUnescape(s string) (string, error) { + return url.QueryUnescape(s) +} diff --git a/util_go18.go b/util_go18.go new file mode 100644 index 00000000..8a37785b --- /dev/null +++ b/util_go18.go @@ -0,0 +1,10 @@ +// +build go1.8 + +package echo + +import "net/url" + +// PathUnescape is wraps `url.PathUnescape` +func PathUnescape(s string) (string, error) { + return url.PathUnescape(s) +}