use clean urls for routing

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2025-12-05 14:16:29 +01:00
parent c99342318f
commit 38eb7fb21b

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"path"
"regexp"
"strings"
@@ -271,7 +272,7 @@ func (rt Router) regexRouteMatcher(pattern string, target url.URL) bool {
}
func prefixRouteMatcher(prefix string, target url.URL) bool {
return strings.HasPrefix(target.Path, prefix) && prefix != "/"
return strings.HasPrefix(path.Clean(target.Path), prefix) && prefix != "/"
}
func singleJoiningSlash(a, b string) string {
@@ -288,7 +289,7 @@ func singleJoiningSlash(a, b string) string {
func queryRouteMatcher(endpoint string, target url.URL) bool {
u, _ := url.Parse(endpoint)
if !strings.HasPrefix(target.Path, u.Path) || endpoint == "/" {
if !strings.HasPrefix(path.Clean(target.Path), u.Path) || endpoint == "/" {
return false
}
q := u.Query()