From 4cae7a26184b98f1fb11ef180a90c5db695ea2d8 Mon Sep 17 00:00:00 2001 From: Abhishek Lekshmanan Date: Thu, 17 Oct 2019 15:10:23 +0200 Subject: [PATCH] rgw: url_encode prefixes if requested for List Objects Also doesn't encode "/" similar to S3 Fixes: https://tracker.ceph.com/issues/41870 Signed-off-by: Abhishek Lekshmanan --- src/rgw/rgw_rest_s3.cc | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 479d6cc3a3363..1d309153fbad3 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -867,7 +867,12 @@ void RGWListBucket_ObjStore_S3::send_common_versioned_response() for (pref_iter = common_prefixes.begin(); pref_iter != common_prefixes.end(); ++pref_iter) { s->formatter->open_array_section("CommonPrefixes"); - s->formatter->dump_string("Prefix", pref_iter->first); + if (encode_key) { + s->formatter->dump_string("Prefix", url_encode(pref_iter->first, false)); + } else { + s->formatter->dump_string("Prefix", pref_iter->first); + } + s->formatter->close_section(); } } @@ -876,6 +881,10 @@ void RGWListBucket_ObjStore_S3::send_common_versioned_response() void RGWListBucket_ObjStore_S3::send_versioned_response() { s->formatter->open_object_section_in_ns("ListVersionsResult", XMLNS_AWS_S3); + if (strcasecmp(encoding_type.c_str(), "url") == 0) { + s->formatter->dump_string("EncodingType", "url"); + encode_key = true; + } RGWListBucket_ObjStore_S3::send_common_versioned_response(); s->formatter->dump_string("KeyMarker", marker.name); s->formatter->dump_string("VersionIdMarker", marker.instance); @@ -888,10 +897,6 @@ void RGWListBucket_ObjStore_S3::send_versioned_response() s->formatter->dump_string("NextVersionIdMarker", next_marker.instance); } } - if (strcasecmp(encoding_type.c_str(), "url") == 0) { - s->formatter->dump_string("EncodingType", "url"); - encode_key = true; - } if (op_ret >= 0) { if (objs_container) { @@ -972,7 +977,11 @@ void RGWListBucket_ObjStore_S3::send_common_response() for (pref_iter = common_prefixes.begin(); pref_iter != common_prefixes.end(); ++pref_iter) { s->formatter->open_array_section("CommonPrefixes"); - s->formatter->dump_string("Prefix", pref_iter->first); + if (encode_key) { + s->formatter->dump_string("Prefix", url_encode(pref_iter->first, false)); + } else { + s->formatter->dump_string("Prefix", pref_iter->first); + } s->formatter->close_section(); } } @@ -998,11 +1007,11 @@ void RGWListBucket_ObjStore_S3::send_response() } s->formatter->open_object_section_in_ns("ListBucketResult", XMLNS_AWS_S3); - RGWListBucket_ObjStore_S3::send_common_response(); if (strcasecmp(encoding_type.c_str(), "url") == 0) { s->formatter->dump_string("EncodingType", "url"); encode_key = true; } + RGWListBucket_ObjStore_S3::send_common_response(); if (op_ret >= 0) { vector::iterator iter; for (iter = objs.begin(); iter != objs.end(); ++iter) { @@ -1115,7 +1124,12 @@ void RGWListBucket_ObjStore_S3v2::send_versioned_response() for (pref_iter = common_prefixes.begin(); pref_iter != common_prefixes.end(); ++pref_iter) { s->formatter->open_array_section("CommonPrefixes"); - s->formatter->dump_string("Prefix", pref_iter->first); + if (encode_key) { + s->formatter->dump_string("Prefix", url_encode(pref_iter->first, false)); + } else { + s->formatter->dump_string("Prefix", pref_iter->first); + } + s->formatter->dump_int("KeyCount",objs.size()); if (start_after_exist) { s->formatter->dump_string("StartAfter", startAfter); @@ -1149,12 +1163,12 @@ void RGWListBucket_ObjStore_S3v2::send_response() } s->formatter->open_object_section_in_ns("ListBucketResult", XMLNS_AWS_S3); - - RGWListBucket_ObjStore_S3::send_common_response(); if (strcasecmp(encoding_type.c_str(), "url") == 0) { s->formatter->dump_string("EncodingType", "url"); encode_key = true; } + + RGWListBucket_ObjStore_S3::send_common_response(); if (op_ret >= 0) { vector::iterator iter; for (iter = objs.begin(); iter != objs.end(); ++iter) { -- 2.39.5