From c4108007cdde7bde4dbd1bc1b587ceece195bd6c Mon Sep 17 00:00:00 2001 From: XZB-1248 <28593573+XZB-1248@users.noreply.github.com> Date: Tue, 14 Mar 2023 12:27:42 +0800 Subject: [PATCH] fix: spaces in filename will be replaced with plus sign (#3841) Co-authored-by: XZB --- drivers/s3/driver.go | 3 ++- server/common/proxy.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/s3/driver.go b/drivers/s3/driver.go index bdcf7ab5..601f5330 100644 --- a/drivers/s3/driver.go +++ b/drivers/s3/driver.go @@ -59,7 +59,8 @@ func (d *S3) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]mo func (d *S3) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) { path := getKey(file.GetPath(), false) - disposition := fmt.Sprintf(`attachment;filename="%s"`, url.QueryEscape(stdpath.Base(path))) + filename := stdpath.Base(path) + disposition := fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, filename, url.PathEscape(filename)) input := &s3.GetObjectInput{ Bucket: &d.Bucket, Key: &path, diff --git a/server/common/proxy.go b/server/common/proxy.go index 142301ab..0489e3fc 100644 --- a/server/common/proxy.go +++ b/server/common/proxy.go @@ -26,8 +26,9 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model. defer func() { _ = link.Data.Close() }() + filename := file.GetName() w.Header().Set("Content-Type", "application/octet-stream") - w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, file.GetName(), url.QueryEscape(file.GetName()))) + w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, filename, url.PathEscape(filename))) w.Header().Set("Content-Length", strconv.FormatInt(file.GetSize(), 10)) if link.Header != nil { // TODO clean header with blacklist or whitelist