mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-21 06:33:11 +00:00
🦟 Fix star routes
This commit is contained in:
parent
0d31dc193c
commit
ad7f4df9a7
@ -59,7 +59,9 @@ func (r *Route) match(path, original string) (match bool, values []string) {
|
|||||||
// '*' wildcard matches any path
|
// '*' wildcard matches any path
|
||||||
} else if r.star {
|
} else if r.star {
|
||||||
values := getAllocFreeParams(1)
|
values := getAllocFreeParams(1)
|
||||||
values[0] = original[1:]
|
if len(original) > 1 {
|
||||||
|
values[0] = original[1:]
|
||||||
|
}
|
||||||
return true, values
|
return true, values
|
||||||
}
|
}
|
||||||
// Does this route have parameters
|
// Does this route have parameters
|
||||||
|
@ -77,6 +77,16 @@ func Test_Route_Match_Star(t *testing.T) {
|
|||||||
body, err = ioutil.ReadAll(resp.Body)
|
body, err = ioutil.ReadAll(resp.Body)
|
||||||
utils.AssertEqual(t, nil, err, "app.Test(req)")
|
utils.AssertEqual(t, nil, err, "app.Test(req)")
|
||||||
utils.AssertEqual(t, "test", getString(body))
|
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) {
|
func Test_Route_Match_Root(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user