all repos — homestead @ 628ce84dd6f2c7baf327f22267cb1bcc45271ab5

Code for my website

join URL paths for go modules correctly

Alin
commit

628ce84dd6f2c7baf327f22267cb1bcc45271ab5

parent

d5e3655f3973cae50c2ea8f06759b206d858668b

1 file changed, 7 insertions(+), 1 deletion(-)

changed files
M domain/web/mux.godomain/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 {