1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-15 01:34:53 +02:00

Fix router not matching param route with trailing slash and implement matching by path+method (#1812)

* when url ends with slash first param route is the match (fix #1804)
* router should check if method is suitable for matching route and if not then continue search in tree (fix #1808)
This commit is contained in:
Martti T
2021-04-27 10:55:31 +03:00
committed by GitHub
parent 3b07058a1d
commit 643066594d
3 changed files with 169 additions and 29 deletions

View File

@ -464,7 +464,9 @@ func TestContextPath(t *testing.T) {
e := New()
r := e.Router()
r.Add(http.MethodGet, "/users/:id", nil)
handler := func(c Context) error { return c.String(http.StatusOK, "OK") }
r.Add(http.MethodGet, "/users/:id", handler)
c := e.NewContext(nil, nil)
r.Find(http.MethodGet, "/users/1", c)
@ -472,7 +474,7 @@ func TestContextPath(t *testing.T) {
assert.Equal("/users/:id", c.Path())
r.Add(http.MethodGet, "/users/:uid/files/:fid", nil)
r.Add(http.MethodGet, "/users/:uid/files/:fid", handler)
c = e.NewContext(nil, nil)
r.Find(http.MethodGet, "/users/1/files/1", c)
assert.Equal("/users/:uid/files/:fid", c.Path())