serenity/Userland/Libraries/LibWeb/URLEncoder.cpp
Luke 70a575d75f 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.
2021-06-01 23:26:03 +04:30

26 lines
674 B
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StringBuilder.h>
#include <AK/URL.h>
#include <LibWeb/URLEncoder.h>
namespace Web {
String urlencode(const Vector<URLQueryParam>& 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, percent_encode_set));
builder.append('=');
builder.append(URL::percent_encode(pairs[i].value, percent_encode_set));
if (i != pairs.size() - 1)
builder.append('&');
}
return builder.to_string();
}
}