From 70a575d75f88282b6c3bce1b52273f8d01c8a8b1 Mon Sep 17 00:00:00 2001 From: Luke Date: Tue, 1 Jun 2021 13:08:30 +0100 Subject: [PATCH] LibWeb: Use correct percent encode set for form submissions We currently only support application/x-www-form-urlencoded for form submissions, which uses a special percent encode set when percent encoding the body/query. However, we were not using this percent encode set. With the new URL implementation, we can now specify the percent encode set to be used, allowing us to use this special percent encode set. This is one of the fixes needed to make the Google cookie consent work. --- Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp | 4 ++-- Userland/Libraries/LibWeb/URLEncoder.cpp | 6 +++--- Userland/Libraries/LibWeb/URLEncoder.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index 53c5c45137..fb104c377a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -105,14 +105,14 @@ void HTMLFormElement::submit_form(RefPtr submitter, bool from_submi }); if (effective_method == "get") { - url.set_query(urlencode(parameters)); + url.set_query(urlencode(parameters, URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded)); } LoadRequest request; request.set_url(url); if (effective_method == "post") { - auto body = urlencode(parameters).to_byte_buffer(); + auto body = urlencode(parameters, URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded).to_byte_buffer(); request.set_method("POST"); request.set_header("Content-Type", "application/x-www-form-urlencoded"); request.set_header("Content-Length", String::number(body.size())); diff --git a/Userland/Libraries/LibWeb/URLEncoder.cpp b/Userland/Libraries/LibWeb/URLEncoder.cpp index bad252e2b5..ed4ece6b79 100644 --- a/Userland/Libraries/LibWeb/URLEncoder.cpp +++ b/Userland/Libraries/LibWeb/URLEncoder.cpp @@ -10,13 +10,13 @@ namespace Web { -String urlencode(const Vector& pairs) +String urlencode(const Vector& pairs, URL::PercentEncodeSet percent_encode_set) { StringBuilder builder; for (size_t i = 0; i < pairs.size(); ++i) { - builder.append(URL::percent_encode(pairs[i].name)); + builder.append(URL::percent_encode(pairs[i].name, percent_encode_set)); builder.append('='); - builder.append(URL::percent_encode(pairs[i].value)); + builder.append(URL::percent_encode(pairs[i].value, percent_encode_set)); if (i != pairs.size() - 1) builder.append('&'); } diff --git a/Userland/Libraries/LibWeb/URLEncoder.h b/Userland/Libraries/LibWeb/URLEncoder.h index 5b6a2268a8..5bd004f560 100644 --- a/Userland/Libraries/LibWeb/URLEncoder.h +++ b/Userland/Libraries/LibWeb/URLEncoder.h @@ -16,6 +16,6 @@ struct URLQueryParam { String value; }; -String urlencode(const Vector&); +String urlencode(const Vector&, URL::PercentEncodeSet); }