From c43d497376f00a7f00a77cde5131eab89f4a4ef0 Mon Sep 17 00:00:00 2001 From: lvshanchun Date: Wed, 29 Nov 2017 11:26:44 +0800 Subject: [PATCH] rgw: add encode_slash param in url_encode when sent request to S3, we should not encode the forward slash character('/') in the object key name, so we need add a encode_slash param in url_encode to decide whether to encode the slash or not. Signed-off-by: lvshanchun --- src/rgw/rgw_common.cc | 13 ++++++------- src/rgw/rgw_common.h | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 7f1769fd0e60a..285724e9d67b2 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -1426,23 +1426,22 @@ static bool char_needs_url_encoding(char c) return false; } -void url_encode(const string& src, string& dst) +void url_encode(const string& src, string& dst, bool encode_slash) { const char *p = src.c_str(); for (unsigned i = 0; i < src.size(); i++, p++) { - if (char_needs_url_encoding(*p)) { + if ((!encode_slash && *p == 0x2F) || !char_needs_url_encoding(*p)) { + dst.append(p, 1); + }else { rgw_uri_escape_char(*p, dst); - continue; } - - dst.append(p, 1); } } -std::string url_encode(const std::string& src) +std::string url_encode(const std::string& src, bool encode_slash) { std::string dst; - url_encode(src, dst); + url_encode(src, dst, encode_slash); return dst; } diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 520fc2bf0e0be..e6f59a86f437f 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -2302,9 +2302,9 @@ extern bool verify_object_permission_no_policy(struct req_state *s, extern void rgw_uri_escape_char(char c, string& dst); extern std::string url_decode(const boost::string_view& src_str, bool in_query = false); -extern void url_encode(const std::string& src, - string& dst); -extern std::string url_encode(const std::string& src); +extern void url_encode(const std::string& src, string& dst, + bool encode_slash = true); +extern std::string url_encode(const std::string& src, bool encode_slash = true); /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */ extern void calc_hmac_sha1(const char *key, int key_len, const char *msg, int msg_len, char *dest); -- 2.39.5