From b00a0737a4c58a400f896c55dee6a6d2579e64e4 Mon Sep 17 00:00:00 2001 From: Max Thomson Date: Thu, 19 Sep 2024 13:47:16 -0700 Subject: [PATCH] contrib/dimfeld/httptreemux.v5: only replace at end of path --- contrib/dimfeld/httptreemux.v5/httptreemux.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/dimfeld/httptreemux.v5/httptreemux.go b/contrib/dimfeld/httptreemux.v5/httptreemux.go index d9ae06e91d..e50c951cb9 100644 --- a/contrib/dimfeld/httptreemux.v5/httptreemux.go +++ b/contrib/dimfeld/httptreemux.v5/httptreemux.go @@ -145,7 +145,10 @@ func getRoute(router *httptreemux.TreeMux, w http.ResponseWriter, req *http.Requ // replace parameter at end of the path, i.e. "../:param" oldP = "/" + v newP = "/:" + k - route = strings.Replace(route, oldP, newP, 1) + if strings.HasSuffix(route, oldP) { + endPos := strings.LastIndex(route, oldP) + route = route[:endPos] + newP + } } return route, true }