diff --git a/AK/URL.cpp b/AK/URL.cpp index 8e6d5f32e01..7c0293255ad 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include namespace AK { @@ -237,7 +236,7 @@ bool URL::parse(const StringView& string) if (state == State::InFragment) m_fragment = String::copy(buffer); if (state == State::InDataPayload) - m_data_payload = urldecode(String::copy(buffer)); + m_data_payload = URL::percent_decode(String::copy(buffer)); if (state == State::InPort) { auto port_opt = String::copy(buffer).to_uint(); if (port_opt.has_value()) diff --git a/AK/URL.h b/AK/URL.h index a14dd7bbd95..e066e885e5a 100644 --- a/AK/URL.h +++ b/AK/URL.h @@ -9,7 +9,6 @@ #include #include -#include namespace AK { @@ -62,8 +61,7 @@ public: String to_string() const; String to_string_encoded() const { - // Exclusion character set is the same JS's encodeURI() uses - return urlencode(to_string(), "#$&+,/:;=?@"); + return percent_encode(to_string(), PercentEncodeSet::EncodeURI); } URL complete_url(const String&) const; diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index dd61bd7d6b1..9d180b6010f 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -12,6 +12,7 @@ #include "ConsoleWidget.h" #include "DownloadWidget.h" #include +#include #include #include #include @@ -39,7 +40,7 @@ URL url_from_user_input(const String& input) { if (input.starts_with("?") && !g_search_engine.is_null()) { auto url = g_search_engine; - url.replace("{}", urlencode(input.substring(1))); + url.replace("{}", URL::percent_encode(input.substring_view(1))); return URL(url); } diff --git a/Userland/Libraries/LibWeb/URLEncoder.cpp b/Userland/Libraries/LibWeb/URLEncoder.cpp index 8e59b723f78..bad252e2b50 100644 --- a/Userland/Libraries/LibWeb/URLEncoder.cpp +++ b/Userland/Libraries/LibWeb/URLEncoder.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include namespace Web { @@ -14,9 +14,9 @@ String urlencode(const Vector& pairs) { StringBuilder builder; for (size_t i = 0; i < pairs.size(); ++i) { - builder.append(urlencode(pairs[i].name)); + builder.append(URL::percent_encode(pairs[i].name)); builder.append('='); - builder.append(urlencode(pairs[i].value)); + builder.append(URL::percent_encode(pairs[i].value)); if (i != pairs.size() - 1) builder.append('&'); } diff --git a/Userland/Services/WebServer/Client.cpp b/Userland/Services/WebServer/Client.cpp index ef40a8de47e..cc990edb20d 100644 --- a/Userland/Services/WebServer/Client.cpp +++ b/Userland/Services/WebServer/Client.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -223,7 +223,7 @@ void Client::handle_directory_listing(const String& requested_path, const String builder.append(""); builder.appendff("
", is_directory ? "folder" : "file"); builder.append(""); builder.append(escape_html_entities(name)); builder.append(" ");