Skip to content

Fix #1493 router loop for param routes #1501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 19, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add test to reproduce router loop for #1493
  • Loading branch information
lammel committed Feb 18, 2020
commit f204b2495d7e50f71e144ad3fed62ac6f91f16cb
20 changes: 20 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,26 @@ func TestRouterParam1466(t *testing.T) {
assert.Equal(t, "self", c.Param("type"))
}

// Issue #1493
func TestRouterParam1493(t *testing.T) {
e := New()
r := e.router

r.Add(http.MethodGet, "/assets/:id", func(c Context) error {
return c.String(http.StatusOK, "assetID")
})

c := e.NewContext(nil, nil).(*context)

// No loop shall occur, param must be empty
r.Find(http.MethodGet, "/assets/3/e", c)
assert.Equal(t, "", c.Param("id"))
assert.Equal(t, 0, c.response.Status)
r.Find(http.MethodGet, "/assets/tree/free", c)
assert.Equal(t, "", c.Param("id"))
assert.Equal(t, 0, c.response.Status)
}

func benchmarkRouterRoutes(b *testing.B, routes []*Route) {
e := New()
r := e.router
Expand Down