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) +}