mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-19 11:19:36 +00:00
Make decode_uri the inverse of encode_uri (#2540)
decode_uri was a byte-for-byte copy of decode_uri_component: it decoded every
%XX, including escapes of the reserved characters that encode_uri leaves
literal. So decode_uri was not the inverse of encode_uri and promoted an
escaped delimiter into a real one -- decode_uri("http://h/a%2Fb") returned
"http://h/a/b". Keep escapes of the reserved set encode_uri preserves, matching
JS decodeURI; non-reserved escapes still decode.
This commit is contained in:
1 parent
d3ff68d28d
commit
2004668509
2 files changed
+29
-1
No files matched your search
@@ -10603,7 +10603,19 @@ inline std::string decode_uri(const std::string &value) {
|
||||
if (value[i] == '%' && i + 2 < value.size()) {
|
||||
auto val = 0;
|
||||
if (detail::from_hex_to_i(value, i + 1, 2, val)) {
|
||||
result += static_cast<char>(val);
|
||||
auto c = static_cast<char>(val);
|
||||
// Keep escapes of the reserved characters that encode_uri leaves
|
||||
// literal, so decode_uri is the inverse of encode_uri and an escaped
|
||||
// delimiter is not promoted into a real one (as with JS decodeURI).
|
||||
if (c == ';' || c == '/' || c == '?' || c == ':' || c == '@' ||
|
||||
c == '&' || c == '=' || c == '+' || c == '$' || c == ',' ||
|
||||
c == '#') {
|
||||
result += value[i];
|
||||
result += value[i + 1];
|
||||
result += value[i + 2];
|
||||
} else {
|
||||
result += c;
|
||||
}
|
||||
i += 2;
|
||||
} else {
|
||||
result += value[i];
|
||||
|
||||
Reference in new issue
Block a user