AK+Everywhere: Replace usages of URLParser::urlencode() and urldecode()
This replaces all occurrences of those functions with the newly implemented functions URL::percent_encode() and URL::percent_decode(). The old functions will be removed in a further commit.
This commit is contained in:
parent
2a6c9bc5f7
commit
a603e69599
Notes:
sideshowbarker
2024-07-18 17:04:40 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/a603e69599c Pull-request: https://github.com/SerenityOS/serenity/pull/7478 Reviewed-by: https://github.com/awesomekling
5 changed files with 9 additions and 11 deletions
|
@ -8,7 +8,6 @@
|
|||
#include <AK/LexicalPath.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/URL.h>
|
||||
#include <AK/URLParser.h>
|
||||
#include <AK/Utf8View.h>
|
||||
|
||||
namespace AK {
|
||||
|
@ -237,7 +236,7 @@ bool URL::parse(const StringView& string)
|
|||
if (state == State::InFragment)
|
||||
m_fragment = String::copy(buffer);
|
||||
if (state == State::InDataPayload)
|
||||
m_data_payload = urldecode(String::copy(buffer));
|
||||
m_data_payload = URL::percent_decode(String::copy(buffer));
|
||||
if (state == State::InPort) {
|
||||
auto port_opt = String::copy(buffer).to_uint();
|
||||
if (port_opt.has_value())
|
||||
|
|
4
AK/URL.h
4
AK/URL.h
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/URLParser.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
@ -62,8 +61,7 @@ public:
|
|||
String to_string() const;
|
||||
String to_string_encoded() const
|
||||
{
|
||||
// Exclusion character set is the same JS's encodeURI() uses
|
||||
return urlencode(to_string(), "#$&+,/:;=?@");
|
||||
return percent_encode(to_string(), PercentEncodeSet::EncodeURI);
|
||||
}
|
||||
|
||||
URL complete_url(const String&) const;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "ConsoleWidget.h"
|
||||
#include "DownloadWidget.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/URL.h>
|
||||
#include <Applications/Browser/TabGML.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Application.h>
|
||||
|
@ -39,7 +40,7 @@ URL url_from_user_input(const String& input)
|
|||
{
|
||||
if (input.starts_with("?") && !g_search_engine.is_null()) {
|
||||
auto url = g_search_engine;
|
||||
url.replace("{}", urlencode(input.substring(1)));
|
||||
url.replace("{}", URL::percent_encode(input.substring_view(1)));
|
||||
return URL(url);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/URLParser.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibWeb/URLEncoder.h>
|
||||
|
||||
namespace Web {
|
||||
|
@ -14,9 +14,9 @@ String urlencode(const Vector<URLQueryParam>& pairs)
|
|||
{
|
||||
StringBuilder builder;
|
||||
for (size_t i = 0; i < pairs.size(); ++i) {
|
||||
builder.append(urlencode(pairs[i].name));
|
||||
builder.append(URL::percent_encode(pairs[i].name));
|
||||
builder.append('=');
|
||||
builder.append(urlencode(pairs[i].value));
|
||||
builder.append(URL::percent_encode(pairs[i].value));
|
||||
if (i != pairs.size() - 1)
|
||||
builder.append('&');
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <AK/MappedFile.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/URLParser.h>
|
||||
#include <AK/URL.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
|
@ -223,7 +223,7 @@ void Client::handle_directory_listing(const String& requested_path, const String
|
|||
builder.append("<tr>");
|
||||
builder.appendff("<td><div class=\"{}\"></div></td>", is_directory ? "folder" : "file");
|
||||
builder.append("<td><a href=\"");
|
||||
builder.append(urlencode(name));
|
||||
builder.append(URL::percent_encode(name));
|
||||
builder.append("\">");
|
||||
builder.append(escape_html_entities(name));
|
||||
builder.append("</a></td><td> </td>");
|
||||
|
|
Loading…
Add table
Reference in a new issue