From 7a9af53b45bcce3bb96ea21d44dc17e891594dda Mon Sep 17 00:00:00 2001 From: chrislu Date: Mon, 17 Nov 2025 12:33:09 -0800 Subject: [PATCH] Sort CommonPrefixes lexicographically to match AWS S3 behavior --- weed/s3api/s3api_object_handlers_list.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/weed/s3api/s3api_object_handlers_list.go b/weed/s3api/s3api_object_handlers_list.go index 0b40d035e..56d77d95c 100644 --- a/weed/s3api/s3api_object_handlers_list.go +++ b/weed/s3api/s3api_object_handlers_list.go @@ -351,12 +351,16 @@ func (s3a *S3ApiServer) listFilerEntries(bucket string, originalPrefix string, m Contents: contents, CommonPrefixes: commonPrefixes, } - // Sort CommonPrefixes lexicographically to match AWS S3 behavior - sort.Slice(response.CommonPrefixes, func(i, j int) bool { return response.CommonPrefixes[i].Prefix < response.CommonPrefixes[j].Prefix }) - if encodingTypeUrl { - response.EncodingType = s3.EncodingTypeUrl + // Sort CommonPrefixes lexicographically to match AWS S3 behavior + sort.Slice(response.CommonPrefixes, func(i, j int) bool { return response.CommonPrefixes[i].Prefix < response.CommonPrefixes[j].Prefix }) + if encodingTypeUrl { + response.EncodingType = s3.EncodingTypeUrl + // URL-encode all common prefixes when EncodingType=url + for i := range response.CommonPrefixes { + response.CommonPrefixes[i].Prefix = urlPathEscape(response.CommonPrefixes[i].Prefix) } - return nil + } + return nil }) return