From b0f3aba97d8b1090ae226f9144716ce417fb91ff Mon Sep 17 00:00:00 2001 From: simpleqt <89645338+simpleqt@users.noreply.github.com> Date: Tue, 15 Sep 2026 01:46:48 +0800 Subject: [PATCH] fix(router): guard Remove against deleting entry 0 on no-match rIndex defaulted to 0 and the delete executed unconditionally. When the normalized lookup path didn't match any stored raw path (e.g. 'users' stored without a leading slash), r.routes[0] was silently deleted while the dead entry remained. --- router.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/router.go b/router.go index 99950aae7..fa88489cb 100644 --- a/router.go +++ b/router.go @@ -439,13 +439,16 @@ func (r *DefaultRouter) Remove(method string, path string) error { } nodeToRemove.setHandler(method, nil) - var rIndex int + var rIndex = -1 for i, rr := range r.routes { if rr.Method == method && rr.Path == path { rIndex = i break } } + if rIndex < 0 { + return nil + } r.routes = append(r.routes[:rIndex], r.routes[rIndex+1:]...) if !nodeToRemove.isHandler && nodeToRemove.isLeaf {