mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-07-21 00:16:32 +02:00
「✨」 feat(http/parsing): full url percent decoding
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/30 09:42:18 by adjoly #+# #+# */
|
||||
/* Updated: 2025/07/08 11:43:21 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/07/15 19:16:59 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,6 +26,21 @@ Delete::Delete(std::string &data, config::Server *srv) {
|
||||
this->parse(data);
|
||||
}
|
||||
|
||||
static std::string urlDecode(const std::string& str) {
|
||||
std::ostringstream decoded;
|
||||
for (size_t i = 0; i < str.length(); ++i) {
|
||||
if (str[i] == '%' && i + 2 < str.length()) {
|
||||
std::string hex = str.substr(i + 1, 2);
|
||||
char decodedChar = static_cast<char>(std::strtol(hex.c_str(), 0, 16));
|
||||
decoded << decodedChar;
|
||||
i += 2;
|
||||
} else {
|
||||
decoded << str[i];
|
||||
}
|
||||
}
|
||||
return decoded.str();
|
||||
}
|
||||
|
||||
void Delete::parse(std::string const &data) {
|
||||
std::istringstream stream(data);
|
||||
std::string line;
|
||||
@ -34,7 +49,7 @@ void Delete::parse(std::string const &data) {
|
||||
std::istringstream line_stream(line);
|
||||
line_stream >> this->_method >> this->_target >> this->_protocol;
|
||||
_method = _sanitizeStr(_method);
|
||||
_target = _sanitizeStr(_target);
|
||||
_target = urlDecode(_sanitizeStr(_target));
|
||||
_protocol = _sanitizeStr(_protocol);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user