Skip to content

Commit

Permalink
🐞 Panic on ":param" gofiber#405
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerr committed May 24, 2020
1 parent 3d2d072 commit 04642a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@ type Route struct {
}

func (r *Route) match(path, original string) (match bool, values []string) {
// Does this route have parameters
if len(r.routeParams) > 0 {
// Match params
if paramPos, match := r.routeParser.getMatch(path, r.use); match {
// Get params from the original path
return match, r.routeParser.paramsForPos(original, paramPos)
}
}
// Is this route a Middleware?
if r.use {
// Single slash will match or path prefix
if r.root || strings.HasPrefix(path, r.path) {
return true, getAllocFreeParams(len(r.routeParser.params))
return true, values
}
// Check for a simple path match
} else if len(r.path) == len(path) && r.path == path {
return true, getAllocFreeParams(len(r.routeParser.params))
return true, values
} else if r.root && path == "/" {
return true, values
}
// '*' wildcard matches any path
if r.star {
return true, []string{utils.TrimLeft(original, '/')}
}
// Does this route have parameters
if len(r.routeParams) > 0 {
// Match params
if paramPos, match := r.routeParser.getMatch(path, r.use); match {
// Get params from the original path
return match, r.routeParser.paramsForPos(original, paramPos)
}
}
// No match
return false, values
}
Expand Down
6 changes: 3 additions & 3 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Test_Route_Match_SameLength(t *testing.T) {

body, err := ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, "", getString(body))
utils.AssertEqual(t, ":param", getString(body))

// with param
resp, err = app.Test(httptest.NewRequest(MethodGet, "/test", nil))
Expand All @@ -53,7 +53,7 @@ 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, "", getString(body))
utils.AssertEqual(t, "*", getString(body))

// with param
resp, err = app.Test(httptest.NewRequest(MethodGet, "/test", nil))
Expand Down Expand Up @@ -121,7 +121,7 @@ func Test_Route_Match_Middleware(t *testing.T) {

body, err := ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, "", getString(body))
utils.AssertEqual(t, "*", getString(body))

// with param
resp, err = app.Test(httptest.NewRequest(MethodGet, "/foo/bar/fasel", nil))
Expand Down

0 comments on commit 04642a3

Please sign in to comment.