diff --git a/ctx.go b/ctx.go index 9dc018f5..78eedc19 100644 --- a/ctx.go +++ b/ctx.go @@ -1069,11 +1069,13 @@ func (c *DefaultCtx) Params(key string, defaultValue ...string) string { if key == "*" || key == "+" { key += "1" } - for i := range c.route.Params { + + route := c.Route() + for i := range route.Params { if len(key) != len(c.route.Params[i]) { continue } - if c.route.Params[i] == key || (!c.app.config.CaseSensitive && utils.EqualFold(c.route.Params[i], key)) { + if route.Params[i] == key || (!c.app.config.CaseSensitive && utils.EqualFold(route.Params[i], key)) { // in case values are not here if len(c.values) <= i || len(c.values[i]) == 0 { break diff --git a/ctx_test.go b/ctx_test.go index 36673f9e..e27aa421 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -2372,6 +2372,25 @@ func Test_Ctx_Params(t *testing.T) { require.Equal(t, StatusOK, resp.StatusCode, "Status code") } +func Test_Ctx_Params_ErrorHandler_Panic_Issue_2832(t *testing.T) { + t.Parallel() + + app := New(Config{ + ErrorHandler: func(c Ctx, _ error) error { + return c.SendString(c.Params("user")) + }, + BodyLimit: 1 * 1024, + }) + + app.Get("/test/:user", func(_ Ctx) error { + return NewError(StatusInternalServerError, "error") + }) + + largeBody := make([]byte, 2*1024) + _, err := app.Test(httptest.NewRequest(MethodGet, "/test/john", bytes.NewReader(largeBody))) + require.ErrorIs(t, err, fasthttp.ErrBodyTooLarge, "app.Test(req)") +} + func Test_Ctx_Params_Case_Sensitive(t *testing.T) { t.Parallel() app := New(Config{CaseSensitive: true})