From f4d6b12072f525ba998c4a261cc75b05c39a5178 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Mon, 19 Jun 2023 13:03:29 +0545 Subject: [PATCH 1/2] also URL encode the prefix without this the prefix in the response would not be URL encoded before: ``` sub-folder <>/sub2/ ``` after ``` sub-folder+%3C%3E/sub2/ ``` --- gofakes3.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gofakes3.go b/gofakes3.go index d0966d8..61a1a0e 100644 --- a/gofakes3.go +++ b/gofakes3.go @@ -257,7 +257,7 @@ func (g *GoFakeS3) listBucket(bucketName string, w http.ResponseWriter, r *http. Contents: objects.Contents, IsTruncated: objects.IsTruncated, Delimiter: prefix.Delimiter, - Prefix: prefix.Prefix, + Prefix: URLEncode(prefix.Prefix), MaxKeys: page.MaxKeys, } From 733861251a0aa395b3d94b32c83a3d112bc8fae5 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Mon, 19 Jun 2023 13:13:08 +0545 Subject: [PATCH 2/2] set encoding type to "url" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit at least for the `mc` client of minio this makes things clearer having a folder/file name in the backend that contains unusual characters e.g. `bucket2/sub-folder <>/a space $%&#.txt` results without this change in this output when running `mc ls` `[2023-06-16 17:19:10 +0545] 11B STANDARD /bucket2/sub-folder+%3C%3E/sub2/a+space+%24%25%26%23.txt` also such a folder/bucket cannot be downloaded using `mc cp` after the change the output of `mc ls` is correct and same as if it connects to AWS S3 `[2023-06-16 17:19:10 +0545] 11B STANDARD a space $%&#.txt` and also the `mc tree -f` output looks correct ``` proxy/bucket2/ └─ sub-folder <> ├─ a space $%&#.txt └─ sub2 └─ a space $%&#.txt ``` --- gofakes3.go | 1 + messages.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gofakes3.go b/gofakes3.go index 61a1a0e..5928bda 100644 --- a/gofakes3.go +++ b/gofakes3.go @@ -280,6 +280,7 @@ func (g *GoFakeS3) listBucket(bucketName string, w http.ResponseWriter, r *http. KeyCount: int64(len(objects.CommonPrefixes) + len(objects.Contents)), StartAfter: q.Get("start-after"), ContinuationToken: q.Get("continuation-token"), + EncodingType: "url", } if objects.NextMarker != "" { // We are just cheating with these continuation tokens; they're just the NextMarker diff --git a/messages.go b/messages.go index cf1847e..d9d2274 100644 --- a/messages.go +++ b/messages.go @@ -248,7 +248,8 @@ type ListBucketResultV2 struct { NextContinuationToken string `xml:"NextContinuationToken,omitempty"` // If StartAfter was sent with the request, it is included in the response. - StartAfter string `xml:"StartAfter,omitempty"` + StartAfter string `xml:"StartAfter,omitempty"` + EncodingType string `xml:"EncodingType,omitempty"` } type DeleteMarker struct {