mirror of
https://github.com/labstack/echo.git
synced 2025-11-25 22:32:23 +02:00
Allow different param names in different methods with same path scheme (#2209)
* Change methodHandler element type to methodContext Signed-off-by: ortyomka <iurin.art@gmail.com> * Allow different param names in the smae path with different methods Signed-off-by: ortyomka <iurin.art@gmail.com> * Rename methodContext to routeMethod Add paramsCount in each node for perfomance Signed-off-by: ortyomka <iurin.art@gmail.com> * Add backtracking to nearest path Signed-off-by: ortyomka <iurin.art@gmail.com> * Remove params from NotAllowed Signed-off-by: ortyomka <iurin.art@gmail.com>
This commit is contained in:
@@ -2318,6 +2318,33 @@ func TestRouterPanicWhenParamNoRootOnlyChildsFailsFind(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #1726
|
||||
func TestRouterDifferentParamsInPath(t *testing.T) {
|
||||
e := New()
|
||||
r := e.router
|
||||
r.Add(http.MethodPut, "/*", func(Context) error {
|
||||
return nil
|
||||
})
|
||||
r.Add(http.MethodPut, "/users/:vid/files/:gid", func(Context) error {
|
||||
return nil
|
||||
})
|
||||
r.Add(http.MethodGet, "/users/:uid/files/:fid", func(Context) error {
|
||||
return nil
|
||||
})
|
||||
c := e.NewContext(nil, nil).(*context)
|
||||
|
||||
r.Find(http.MethodGet, "/users/1/files/2", c)
|
||||
assert.Equal(t, "1", c.Param("uid"))
|
||||
assert.Equal(t, "2", c.Param("fid"))
|
||||
|
||||
r.Find(http.MethodGet, "/users/1/shouldBacktrackToFirstAnyRouteAnd405", c)
|
||||
assert.Equal(t, "/*", c.Path())
|
||||
|
||||
r.Find(http.MethodPut, "/users/3/files/4", c)
|
||||
assert.Equal(t, "3", c.Param("vid"))
|
||||
assert.Equal(t, "4", c.Param("gid"))
|
||||
}
|
||||
|
||||
func TestRouterHandleMethodOptions(t *testing.T) {
|
||||
e := New()
|
||||
r := e.router
|
||||
@@ -2380,7 +2407,7 @@ func TestRouterHandleMethodOptions(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tc.expectStatus, rec.Code)
|
||||
}
|
||||
assert.Equal(t, tc.expectAllowHeader, c.Response().Header().Get("Allow"))
|
||||
assert.Equal(t, tc.expectAllowHeader, c.Response().Header().Get(HeaderAllow))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user