From fde3a7f74f4bd8602daeba0359ceedd4fe54a367 Mon Sep 17 00:00:00 2001 From: BrunoF2P Date: Tue, 24 Nov 2026 00:17:39 -0300 Subject: [PATCH 1/2] fix(context): clear pathValues backing array in Context.Reset() --- context.go | 1 + context_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/context.go b/context.go index 9be52f0aa..7f4164ac3 100644 --- a/context.go +++ b/context.go @@ -153,6 +153,7 @@ func (c *Context) Reset(r *http.Request, w http.ResponseWriter) { c.dsw = delayedStatusWriter{} c.path = "" // NOTE: empty by setting length to 0. PathValues has to have capacity of c.echo.contextPathParamAllocSize at all times + clear(*c.pathValues) *c.pathValues = (*c.pathValues)[:0] } diff --git a/context_test.go b/context_test.go index 9b2b59e99..02316e770 100644 --- a/context_test.go +++ b/context_test.go @@ -1822,3 +1822,21 @@ func TestRouteInfo(t *testing.T) { orgRI.Name = "changed" assert.NotEqual(t, expect, c.RouteInfo()) } + +func TestContextResetClearsPathValuesBackingArray(t *testing.T) { + e := New() + c := e.NewContext(nil, nil) + c.SetPathValues(PathValues{ + {Name: "id", Value: "12345"}, + {Name: "token", Value: "secret-value"}, + }) + + origCap := cap(*c.pathValues) + c.Reset(nil, nil) + + assert.Empty(t, *c.pathValues) + assert.Equal(t, origCap, cap(*c.pathValues)) + for i, pv := range (*c.pathValues)[:cap(*c.pathValues)] { + assert.Equal(t, PathValue{}, pv, "pathValues backing array element %d should be zeroed", i) + } +} From 70794f4a6b1a0747597c47d48cbd310ae6e63e09 Mon Sep 17 00:00:00 2001 From: BrunoF2P Date: Tue, 24 Nov 2026 00:39:44 -0300 Subject: [PATCH 2/2] fix(context): clear pathValues through full slice capacity --- context.go | 2 +- context_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index 7f4164ac3..d81176852 100644 --- a/context.go +++ b/context.go @@ -153,7 +153,7 @@ func (c *Context) Reset(r *http.Request, w http.ResponseWriter) { c.dsw = delayedStatusWriter{} c.path = "" // NOTE: empty by setting length to 0. PathValues has to have capacity of c.echo.contextPathParamAllocSize at all times - clear(*c.pathValues) + clear((*c.pathValues)[:cap(*c.pathValues)]) *c.pathValues = (*c.pathValues)[:0] } diff --git a/context_test.go b/context_test.go index 02316e770..159f703be 100644 --- a/context_test.go +++ b/context_test.go @@ -1830,6 +1830,10 @@ func TestContextResetClearsPathValuesBackingArray(t *testing.T) { {Name: "id", Value: "12345"}, {Name: "token", Value: "secret-value"}, }) + // Shortening the slice leaves the previous second element in spare capacity. + c.SetPathValues(PathValues{ + {Name: "id", Value: "67890"}, + }) origCap := cap(*c.pathValues) c.Reset(nil, nil)