1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-05 00:58:47 +02:00

param wildcard capture fixed to *

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-10-10 18:36:48 -07:00
parent 8623669cbc
commit 2eb87f8036
4 changed files with 6 additions and 6 deletions

View File

@ -382,7 +382,7 @@ func (e *Echo) Match(methods []string, path string, handler HandlerFunc, middlew
// provided root directory. // provided root directory.
func (e *Echo) Static(prefix, root string) { func (e *Echo) Static(prefix, root string) {
e.GET(prefix+"*", func(c Context) error { e.GET(prefix+"*", func(c Context) error {
return c.File(path.Join(root, c.Param("_*"))) return c.File(path.Join(root, c.Param("*")))
}) })
} }

View File

@ -70,7 +70,7 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
fs := http.Dir(config.Root) fs := http.Dir(config.Root)
p := c.Request().URL.Path p := c.Request().URL.Path
if strings.Contains(c.Path(), "*") { // If serving from a group, e.g. `/static*`. if strings.Contains(c.Path(), "*") { // If serving from a group, e.g. `/static*`.
p = c.Param("_*") p = c.Param("*")
} }
file := path.Clean(p) file := path.Clean(p)
f, err := fs.Open(file) f, err := fs.Open(file)

View File

@ -81,7 +81,7 @@ func (r *Router) Add(method, path string, h HandlerFunc, e *Echo) {
r.insert(method, path[:i], nil, pkind, ppath, pnames, e) r.insert(method, path[:i], nil, pkind, ppath, pnames, e)
} else if path[i] == '*' { } else if path[i] == '*' {
r.insert(method, path[:i], nil, skind, "", nil, e) r.insert(method, path[:i], nil, skind, "", nil, e)
pnames = append(pnames, "_*") pnames = append(pnames, "*")
r.insert(method, path[:i+1], h, akind, ppath, pnames, e) r.insert(method, path[:i+1], h, akind, ppath, pnames, e)
return return
} }

View File

@ -350,10 +350,10 @@ func TestRouterMatchAny(t *testing.T) {
assert.Equal(t, "", c.Param("_*")) assert.Equal(t, "", c.Param("_*"))
r.Find(GET, "/download", c) r.Find(GET, "/download", c)
assert.Equal(t, "download", c.Param("_*")) assert.Equal(t, "download", c.Param("*"))
r.Find(GET, "/users/joe", c) r.Find(GET, "/users/joe", c)
assert.Equal(t, "joe", c.Param("_*")) assert.Equal(t, "joe", c.Param("*"))
} }
func TestRouterMicroParam(t *testing.T) { func TestRouterMicroParam(t *testing.T) {
@ -483,7 +483,7 @@ func TestRouterPriority(t *testing.T) {
r.Find(GET, "/users/joe/books", c) r.Find(GET, "/users/joe/books", c)
c.handler(c) c.handler(c)
assert.Equal(t, 7, c.Get("g")) assert.Equal(t, 7, c.Get("g"))
assert.Equal(t, "joe/books", c.Param("_*")) assert.Equal(t, "joe/books", c.Param("*"))
} }
// Issue #372 // Issue #372