1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-19 13:07:52 +00:00

🦟 Fix star routes

This commit is contained in:
ReneWerner87 2020-09-02 20:59:42 +02:00
parent 0d31dc193c
commit ad7f4df9a7
2 changed files with 13 additions and 1 deletions

View File

@ -59,7 +59,9 @@ func (r *Route) match(path, original string) (match bool, values []string) {
// '*' wildcard matches any path
} else if r.star {
values := getAllocFreeParams(1)
values[0] = original[1:]
if len(original) > 1 {
values[0] = original[1:]
}
return true, values
}
// Does this route have parameters

View File

@ -77,6 +77,16 @@ func Test_Route_Match_Star(t *testing.T) {
body, err = ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, "test", getString(body))
// without parameter
route := Route{
star: true,
path: "/*",
routeParser: routeParser{},
}
match, params := route.match("", "")
utils.AssertEqual(t, true, match)
utils.AssertEqual(t, []string{""}, params)
}
func Test_Route_Match_Root(t *testing.T) {