Skip to content

Commit

Permalink
🦟 Fix star routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneWerner87 committed Sep 2, 2020
1 parent 0d31dc1 commit ad7f4df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ad7f4df

Please sign in to comment.