Skip to content

Commit 269dfcc

Browse files
authored
Set maxParam with SetParamNames (#1535)
* Set maxParam with SetParamNames Fixes #1492 * Revert go.mod
1 parent 5428358 commit 269dfcc

File tree

4 files changed

+4
-11
lines changed

4 files changed

+4
-11
lines changed

bind_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ func TestBindbindData(t *testing.T) {
332332

333333
func TestBindParam(t *testing.T) {
334334
e := New()
335-
*e.maxParam = 2
336335
req := httptest.NewRequest(GET, "/", nil)
337336
rec := httptest.NewRecorder()
338337
c := e.NewContext(req, rec)
@@ -363,7 +362,6 @@ func TestBindParam(t *testing.T) {
363362
// Bind something with param and post data payload
364363
body := bytes.NewBufferString(`{ "name": "Jon Snow" }`)
365364
e2 := New()
366-
*e2.maxParam = 2
367365
req2 := httptest.NewRequest(POST, "/", body)
368366
req2.Header.Set(HeaderContentType, MIMEApplicationJSON)
369367

context.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,15 @@ func (c *context) ParamNames() []string {
310310

311311
func (c *context) SetParamNames(names ...string) {
312312
c.pnames = names
313+
*c.echo.maxParam = len(names)
313314
}
314315

315316
func (c *context) ParamValues() []string {
316317
return c.pvalues[:len(c.pnames)]
317318
}
318319

319320
func (c *context) SetParamValues(values ...string) {
320-
// NOTE: Don't just set c.pvalues = values, because it has to have length c.echo.maxParam at all times
321-
for i, val := range values {
322-
c.pvalues[i] = val
323-
}
321+
c.pvalues = values
324322
}
325323

326324
func (c *context) QueryParam(name string) string {

context_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ func (responseWriterErr) WriteHeader(statusCode int) {
9393

9494
func TestContext(t *testing.T) {
9595
e := New()
96-
*e.maxParam = 1
9796
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(userJSON))
9897
rec := httptest.NewRecorder()
9998
c := e.NewContext(req, rec).(*context)
@@ -472,7 +471,6 @@ func TestContextPath(t *testing.T) {
472471

473472
func TestContextPathParam(t *testing.T) {
474473
e := New()
475-
*e.maxParam = 2
476474
req := httptest.NewRequest(http.MethodGet, "/", nil)
477475
c := e.NewContext(req, nil)
478476

@@ -491,7 +489,8 @@ func TestContextPathParam(t *testing.T) {
491489

492490
func TestContextGetAndSetParam(t *testing.T) {
493491
e := New()
494-
*e.maxParam = 2
492+
r := e.Router()
493+
r.Add(http.MethodGet, "/:foo", func(Context) error { return nil })
495494
req := httptest.NewRequest(http.MethodGet, "/:foo", nil)
496495
c := e.NewContext(req, nil)
497496
c.SetParamNames("foo")

middleware/jwt_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ func TestJWTRace(t *testing.T) {
6060

6161
func TestJWT(t *testing.T) {
6262
e := echo.New()
63-
r := e.Router()
64-
r.Add("GET", "/:jwt", func(echo.Context) error { return nil })
6563
handler := func(c echo.Context) error {
6664
return c.String(http.StatusOK, "test")
6765
}

0 commit comments

Comments
 (0)