LibWeb: Use the URL encoder from AK instead of rolling a custom one

This commit is contained in:
Andreas Kling 2020-06-15 17:55:27 +02:00
parent d883607e8f
commit 84f8c91a6f
Notes: sideshowbarker 2024-07-19 05:38:24 +09:00
3 changed files with 6 additions and 23 deletions

View file

@ -69,7 +69,7 @@ void HTMLFormElement::submit(RefPtr<HTMLInputElement> submitter)
return IterationDecision::Continue;
});
url.set_query(url_encode(parameters));
url.set_query(urlencode(parameters));
// FIXME: We shouldn't let the form just do this willy-nilly.
document().frame()->page().load(url);

View file

@ -25,34 +25,18 @@
*/
#include <AK/StringBuilder.h>
#include <AK/URLParser.h>
#include <LibWeb/URLEncoder.h>
namespace Web {
String url_encode(const StringView& view)
{
StringBuilder builder;
for (char c : view) {
if (c == ' ') {
builder.append('+');
} else if (c == '*' || c == '-' || c == '.' || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= 'a' && c <= 'z')) {
builder.append(c);
} else {
builder.appendf("%%%02X", c);
}
}
return builder.to_string();
}
String url_encode(const Vector<URLQueryParam>& pairs)
String urlencode(const Vector<URLQueryParam>& pairs)
{
StringBuilder builder;
for (size_t i = 0; i < pairs.size(); ++i) {
builder.append(url_encode(pairs[i].name));
builder.append(urlencode(pairs[i].name));
builder.append('=');
builder.append(url_encode(pairs[i].value));
builder.append(urlencode(pairs[i].value));
if (i != pairs.size() - 1)
builder.append('&');
}

View file

@ -36,8 +36,7 @@ struct URLQueryParam {
String value;
};
String url_encode(const StringView&);
String url_encode(const Vector<URLQueryParam>&);
String urlencode(const Vector<URLQueryParam>&);
}