diff options
author | GeekFiftyFive <amylouisepellatt@gmail.com> | 2022-03-31 16:29:25 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-02 18:43:15 +0200 |
commit | 737f5b26b7fb5cc31dfaf7eb75422a9b09019d17 (patch) | |
tree | d65cf3bcf8bbee8530913c8b04192a5eb1175c37 /AK | |
parent | 58398b1e127f1428261f4b86230c411573fb6426 (diff) | |
download | serenity-737f5b26b7fb5cc31dfaf7eb75422a9b09019d17.zip |
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.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/URL.cpp | 8 | ||||
-rw-r--r-- | AK/URL.h | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/AK/URL.cpp b/AK/URL.cpp index dfc68bbd7e..4b6932c432 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -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(); } @@ -104,7 +104,7 @@ public: static u16 default_port_for_scheme(StringView); static bool is_special_scheme(StringView); - static String percent_encode(StringView input, PercentEncodeSet set = PercentEncodeSet::Userinfo); + static String percent_encode(StringView input, PercentEncodeSet set = PercentEncodeSet::Userinfo, StringView reserved_chars = {}); static String percent_decode(StringView input); bool operator==(URL const& other) const { return equals(other, ExcludeFragment::No); } @@ -122,7 +122,7 @@ private: bool compute_validity() const; String serialize_data_url() const; - static void append_percent_encoded_if_necessary(StringBuilder&, u32 code_point, PercentEncodeSet set = PercentEncodeSet::Userinfo); + static void append_percent_encoded_if_necessary(StringBuilder&, u32 code_point, PercentEncodeSet set = PercentEncodeSet::Userinfo, StringView reserved_chars = {}); static void append_percent_encoded(StringBuilder&, u32 code_point); bool m_valid { false }; |