From 0589d145cd0822eb9f7979e6d54e689de5104fa5 Mon Sep 17 00:00:00 2001 From: huberyxxiao Date: Mon, 15 Jul 2024 19:26:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dqt=E7=8E=AF=E5=A2=83=E4=B8=8B?= =?UTF-8?q?encode=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/cos_defines.h | 2 +- include/util/codec_util.h | 2 ++ src/util/codec_util.cpp | 9 +++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/cos_defines.h b/include/cos_defines.h index ad1a075..02b8fcf 100644 --- a/include/cos_defines.h +++ b/include/cos_defines.h @@ -11,7 +11,7 @@ namespace qcloud_cos { -#define COS_CPP_SDK_VERSON "v5.5.12" +#define COS_CPP_SDK_VERSON "v5.5.13" /// 路径分隔符 const char kPathDelimiter[] = "/"; diff --git a/include/util/codec_util.h b/include/util/codec_util.h index e51d809..cd9f8b0 100644 --- a/include/util/codec_util.h +++ b/include/util/codec_util.h @@ -32,6 +32,8 @@ class CodecUtil { static void BinToHex(const unsigned char* bin, unsigned int binLen, char* hex); + static bool IsalnumAscii(int c); + static std::string EncodeKey(const std::string& key); /** diff --git a/src/util/codec_util.cpp b/src/util/codec_util.cpp index 9257158..faf6117 100644 --- a/src/util/codec_util.cpp +++ b/src/util/codec_util.cpp @@ -30,11 +30,16 @@ void CodecUtil::BinToHex(const unsigned char* bin, unsigned int binLen, } } +bool CodecUtil::IsalnumAscii(int c) { + // 使用 ASCII 码范围判断是否是字母或数字 + return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'); +} + std::string CodecUtil::EncodeKey(const std::string& key) { std::string encodedKey = ""; std::size_t length = key.length(); for (size_t i = 0; i < length; ++i) { - if (isalnum((unsigned char)key[i]) || (key[i] == '-') || (key[i] == '_') || + if (IsalnumAscii((unsigned char)key[i]) || (key[i] == '-') || (key[i] == '_') || (key[i] == '.') || (key[i] == '~') || (key[i] == '/')) { encodedKey += key[i]; } else { @@ -50,7 +55,7 @@ std::string CodecUtil::UrlEncode(const std::string& str) { std::string encodedUrl = ""; std::size_t length = str.length(); for (size_t i = 0; i < length; ++i) { - if (isalnum((unsigned char)str[i]) || (str[i] == '-') || (str[i] == '_') || + if (IsalnumAscii((unsigned char)str[i]) || (str[i] == '-') || (str[i] == '_') || (str[i] == '.') || (str[i] == '~')) { encodedUrl += str[i]; } else {