From 0542fc0ba43740c967414eebd156bac86ad80376 Mon Sep 17 00:00:00 2001 From: Sergio Date: Wed, 11 Mar 2026 11:37:07 -0700 Subject: [PATCH] fix(tus): preserve percent-encoded upload paths in Location header (#5817) --- http/tus_handlers.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/http/tus_handlers.go b/http/tus_handlers.go index 68931f5d..0b7bcbb4 100644 --- a/http/tus_handlers.go +++ b/http/tus_handlers.go @@ -5,10 +5,10 @@ import ( "fmt" "io" "net/http" - "net/url" "os" "path/filepath" "strconv" + "strings" "time" "github.com/spf13/afero" @@ -112,12 +112,12 @@ func tusPostHandler(cache UploadCache) handleFunc { // Enables the user to utilize the PATCH endpoint for uploading file data cache.Register(file.RealPath(), uploadLength) - path, err := url.JoinPath("/", d.server.BaseURL, "/api/tus", r.URL.Path) - if err != nil { - return http.StatusBadRequest, fmt.Errorf("invalid path: %w", err) + basePath := "/" + strings.Trim(strings.TrimSpace(d.server.BaseURL), "/") + if basePath == "/" { + basePath = "" } - w.Header().Set("Location", path) + w.Header().Set("Location", basePath+"/api/tus"+r.URL.EscapedPath()) return http.StatusCreated, nil }) }