1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +00:00

AK+LibHTTP: Ensure plus signs are percent encoded in query string

Adds a new optional parameter 'reserved_chars' to
AK::URL::percent_encode. This new optional parameter allows the caller
to specify custom characters to be percent encoded. This is then used
to percent encode plus signs by HttpRequest::to_raw_request.
This commit is contained in:
GeekFiftyFive 2022-03-31 16:29:25 +01:00 committed by Andreas Kling
parent 58398b1e12
commit 737f5b26b7
3 changed files with 7 additions and 7 deletions

View file

@ -395,19 +395,19 @@ constexpr bool code_point_is_in_percent_encode_set(u32 code_point, URL::PercentE
}
}
void URL::append_percent_encoded_if_necessary(StringBuilder& builder, u32 code_point, URL::PercentEncodeSet set)
void URL::append_percent_encoded_if_necessary(StringBuilder& builder, u32 code_point, URL::PercentEncodeSet set, StringView reserved_chars)
{
if (code_point_is_in_percent_encode_set(code_point, set))
if (code_point_is_in_percent_encode_set(code_point, set) || (!reserved_chars.is_null() && reserved_chars.contains(code_point)))
append_percent_encoded(builder, code_point);
else
builder.append_code_point(code_point);
}
String URL::percent_encode(StringView input, URL::PercentEncodeSet set)
String URL::percent_encode(StringView input, URL::PercentEncodeSet set, StringView reserved_chars)
{
StringBuilder builder;
for (auto code_point : Utf8View(input)) {
append_percent_encoded_if_necessary(builder, code_point, set);
append_percent_encoded_if_necessary(builder, code_point, set, reserved_chars);
}
return builder.to_string();
}