Skip to content

Commit ad5f0c4

Browse files
Merge pull request #165 from tencentyun/feature_huberyxxiao_ba149772
修复qt环境下encode问题
2 parents d1063e7 + b36da04 commit ad5f0c4

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

include/cos_defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace qcloud_cos {
1313

14-
#define COS_CPP_SDK_VERSON "v5.5.12"
14+
#define COS_CPP_SDK_VERSON "v5.5.13"
1515

1616
/// 路径分隔符
1717
const char kPathDelimiter[] = "/";

include/util/codec_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class CodecUtil {
3232
static void BinToHex(const unsigned char* bin, unsigned int binLen,
3333
char* hex);
3434

35+
static bool IsalnumAscii(int c);
36+
3537
static std::string EncodeKey(const std::string& key);
3638

3739
/**

src/util/codec_util.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ void CodecUtil::BinToHex(const unsigned char* bin, unsigned int binLen,
3030
}
3131
}
3232

33+
bool CodecUtil::IsalnumAscii(int c) {
34+
// 使用 ASCII 码范围判断是否是字母或数字
35+
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9');
36+
}
37+
3338
std::string CodecUtil::EncodeKey(const std::string& key) {
3439
std::string encodedKey = "";
3540
std::size_t length = key.length();
3641
for (size_t i = 0; i < length; ++i) {
37-
if (isalnum((unsigned char)key[i]) || (key[i] == '-') || (key[i] == '_') ||
42+
if (IsalnumAscii((unsigned char)key[i]) || (key[i] == '-') || (key[i] == '_') ||
3843
(key[i] == '.') || (key[i] == '~') || (key[i] == '/')) {
3944
encodedKey += key[i];
4045
} else {
@@ -50,7 +55,7 @@ std::string CodecUtil::UrlEncode(const std::string& str) {
5055
std::string encodedUrl = "";
5156
std::size_t length = str.length();
5257
for (size_t i = 0; i < length; ++i) {
53-
if (isalnum((unsigned char)str[i]) || (str[i] == '-') || (str[i] == '_') ||
58+
if (IsalnumAscii((unsigned char)str[i]) || (str[i] == '-') || (str[i] == '_') ||
5459
(str[i] == '.') || (str[i] == '~')) {
5560
encodedUrl += str[i];
5661
} else {

0 commit comments

Comments
 (0)