summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-15 17:55:27 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-15 17:56:00 +0200
commit84f8c91a6fa12f845ff81a4ece8d68ec331a0217 (patch)
tree5dbc3f8ad0635d8c659745d78fc007e2c72edeb4 /Libraries
parentd883607e8f7e968dce894780936e40df8acdb940 (diff)
downloadserenity-84f8c91a6fa12f845ff81a4ece8d68ec331a0217.zip
LibWeb: Use the URL encoder from AK instead of rolling a custom one
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibWeb/DOM/HTMLFormElement.cpp2
-rw-r--r--Libraries/LibWeb/URLEncoder.cpp24
-rw-r--r--Libraries/LibWeb/URLEncoder.h3
3 files changed, 6 insertions, 23 deletions
diff --git a/Libraries/LibWeb/DOM/HTMLFormElement.cpp b/Libraries/LibWeb/DOM/HTMLFormElement.cpp
index 5028ac0db3..397391331a 100644
--- a/Libraries/LibWeb/DOM/HTMLFormElement.cpp
+++ b/Libraries/LibWeb/DOM/HTMLFormElement.cpp
@@ -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);
diff --git a/Libraries/LibWeb/URLEncoder.cpp b/Libraries/LibWeb/URLEncoder.cpp
index e760082fdc..a6be0174ea 100644
--- a/Libraries/LibWeb/URLEncoder.cpp
+++ b/Libraries/LibWeb/URLEncoder.cpp
@@ -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('&');
}
diff --git a/Libraries/LibWeb/URLEncoder.h b/Libraries/LibWeb/URLEncoder.h
index 61cb8b34dd..b12cf2e29d 100644
--- a/Libraries/LibWeb/URLEncoder.h
+++ b/Libraries/LibWeb/URLEncoder.h
@@ -36,8 +36,7 @@ struct URLQueryParam {
String value;
};
-String url_encode(const StringView&);
-String url_encode(const Vector<URLQueryParam>&);
+String urlencode(const Vector<URLQueryParam>&);
}