Skip to content

Commit

Permalink
contrib/dimfeld/httptreemux.v5: only replace at end of path
Browse files Browse the repository at this point in the history
  • Loading branch information
MNThomson authored and darccio committed Oct 22, 2024
1 parent b42c15f commit b00a073
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion contrib/dimfeld/httptreemux.v5/httptreemux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b00a073

Please sign in to comment.