mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
LibWeb: Use the URL encoder from AK instead of rolling a custom one
This commit is contained in:
parent
d883607e8f
commit
84f8c91a6f
Notes:
sideshowbarker
2024-07-19 05:38:24 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/84f8c91a6fa
3 changed files with 6 additions and 23 deletions
|
@ -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);
|
||||
|
|
|
@ -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('&');
|
||||
}
|
||||
|
|
|
@ -36,8 +36,7 @@ struct URLQueryParam {
|
|||
String value;
|
||||
};
|
||||
|
||||
String url_encode(const StringView&);
|
||||
String url_encode(const Vector<URLQueryParam>&);
|
||||
String urlencode(const Vector<URLQueryParam>&);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue