From 4de060daa64a87c27a37796627b2e2a491f14b83 Mon Sep 17 00:00:00 2001 From: chrislu Date: Wed, 5 Jan 2022 03:57:24 -0800 Subject: [PATCH] mount: skip special character in the filenames fix https://github.com/chrislusf/seaweedfs/issues/2559 --- weed/operation/upload_content.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.go index ade324005..569a54372 100644 --- a/weed/operation/upload_content.go +++ b/weed/operation/upload_content.go @@ -4,6 +4,10 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" + "github.com/chrislusf/seaweedfs/weed/security" + "github.com/chrislusf/seaweedfs/weed/util" "io" "mime" "mime/multipart" @@ -12,11 +16,6 @@ import ( "path/filepath" "strings" "time" - - "github.com/chrislusf/seaweedfs/weed/glog" - "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" - "github.com/chrislusf/seaweedfs/weed/security" - "github.com/chrislusf/seaweedfs/weed/util" ) type UploadOption struct { @@ -71,7 +70,7 @@ func init() { }} } -var fileNameEscaper = strings.NewReplacer(`\`, `\\`, `"`, `\"`) +var fileNameEscaper = strings.NewReplacer(`\`, `\\`, `"`, `\"`, "\n", "") // Upload sends a POST request to a volume server to upload the content with adjustable compression level func UploadData(data []byte, option *UploadOption) (uploadResult *UploadResult, err error) { @@ -217,7 +216,8 @@ func upload_content(fillBufferFunction func(w io.Writer) error, originalDataSize defer PutBuffer(buf) body_writer := multipart.NewWriter(buf) h := make(textproto.MIMEHeader) - h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, fileNameEscaper.Replace(option.Filename))) + filename := fileNameEscaper.Replace(option.Filename) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, filename)) h.Set("Idempotency-Key", option.UploadUrl) if option.MimeType == "" { option.MimeType = mime.TypeByExtension(strings.ToLower(filepath.Ext(option.Filename)))