join URL paths for go modules correctly
1 file changed, 7 insertions(+), 1 deletion(-)
changed files
M domain/web/mux.go → domain/web/mux.go
@@ -2,6 +2,7 @@ package website import ( "net/http" + "net/url" "regexp" "slices" "strings"@@ -16,6 +17,7 @@ ihttp "alin.ovh/homestead/shared/http" ) var ( + ErrCanonPath = ihttp.NewError("Error canonicalising path", http.StatusInternalServerError) ErrReadingFile = ihttp.NewError("Error reading file", http.StatusInternalServerError) ErrNotFound = ihttp.NewError("File not found", http.StatusNotFound) ErrRenderFailure = ihttp.NewError("Error rendering template", http.StatusInternalServerError)@@ -45,7 +47,11 @@ func (website *Website) ServeHTTP(w http.ResponseWriter, r *http.Request) error { urlPath := r.URL.Path if r.URL.Query().Has("go-get") && r.URL.Query().Get("go-get") == "1" { - urlPath = "/go" + r.URL.Path + var err error + urlPath, err = url.JoinPath("/go", r.URL.Path) + if err != nil { + return ErrCanonPath.WithCause(err) + } } urlPath, shouldRedirect := website.reader.CanonicalisePath(urlPath) if shouldRedirect {