oat++, url中空格解码

oattp 1.3.0版本,前端URL中传时间(格式:yyyy-MM-dd hh:mm:ss),后端空格没有解码

oatpp的QueryParams 时间中空格没有解码出来 "2025:12:17 %2000:00:00"

%20就是空格

此问题是1.3.0版本中已知的问题(1.4.0中已修复),需要手动解码:

cpp 复制代码
oatpp::String urlDecode(const oatpp::String& encoded) {  
    if (!encoded) return nullptr;  
      
    std::string decoded;  
    for (size_t i = 0; i < encoded->size(); ++i) {  
        if (encoded->data()[i] == '%' && i + 2 < encoded->size()) {  
            // 解码 %XX 格式  
            std::string hex = encoded->substr(i + 1, 2)->std_str();  
            char c = static_cast<char>(std::stoi(hex, nullptr, 16));  
            decoded += c;  
            i += 2;  
        } else if (encoded->data()[i] == '+') {  
            // + 号解码为空格  
            decoded += ' ';  
        } else {  
            decoded += encoded->data()[i];  
        }  
    }  
    return oatpp::String(decoded);  
}