mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
70a575d75f
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.
26 lines
674 B
C++
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();
|
|
}
|
|
|
|
}
|