Fix http url path and component's coding (#3237 #3181)

This commit is contained in:
sandro-qiang
2024-01-28 19:18:36 +08:00
committed by GitHub
parent cfe9a31ca6
commit ceae040a7a
8 changed files with 130 additions and 10 deletions

View File

@@ -695,10 +695,34 @@ string HttpSession::urlDecode(const string &str) {
return ret;
}
string HttpSession::urlDecodePath(const string &str) {
auto ret = strCoding::UrlDecodePath(str);
#ifdef _WIN32
GET_CONFIG(string, charSet, Http::kCharSet);
bool isGb2312 = !strcasecmp(charSet.data(), "gb2312");
if (isGb2312) {
ret = strCoding::UTF8ToGB2312(ret);
}
#endif // _WIN32
return ret;
}
string HttpSession::urlDecodeComponent(const string &str) {
auto ret = strCoding::UrlDecodeComponent(str);
#ifdef _WIN32
GET_CONFIG(string, charSet, Http::kCharSet);
bool isGb2312 = !strcasecmp(charSet.data(), "gb2312");
if (isGb2312) {
ret = strCoding::UTF8ToGB2312(ret);
}
#endif // _WIN32
return ret;
}
void HttpSession::urlDecode(Parser &parser) {
parser.setUrl(urlDecode(parser.url()));
parser.setUrl(urlDecodePath(parser.url()));
for (auto &pr : _parser.getUrlArgs()) {
const_cast<string &>(pr.second) = urlDecode(pr.second);
const_cast<string &>(pr.second) = urlDecodeComponent(pr.second);
}
}