fix: 修复 POP 签名 percentEncode 使用 Unicode 字母集导致非 ASCII 字符未编码的问题
This commit is contained in:
@@ -26,6 +26,8 @@ struct VODSignature {
|
||||
|
||||
let stringToSign = "\(method)&%2F&\(percentEncode(canonicalQuery))"
|
||||
|
||||
print("[VODSignature] stringToSign: \(stringToSign)")
|
||||
|
||||
guard let keyData = "\(accessKeySecret)&".data(using: .utf8) else {
|
||||
throw VODSignatureError.invalidKey
|
||||
}
|
||||
@@ -40,7 +42,15 @@ struct VODSignature {
|
||||
}
|
||||
|
||||
private static func percentEncode(_ value: String) -> String {
|
||||
let allowed = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~")
|
||||
return value.addingPercentEncoding(withAllowedCharacters: allowed) ?? value
|
||||
let allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~"
|
||||
var result = ""
|
||||
for char in value.utf8 {
|
||||
if allowed.utf8.contains(char) {
|
||||
result.append(Character(UnicodeScalar(char)))
|
||||
} else {
|
||||
result.append(String(format: "%%%02X", char))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user