mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
AK: Remove URL::ApplyPercentEncoding
Everywhere only ever expects percent encoding to occur, so let's just remove this flag altogether. At the same time, replace some DeprecatedString with StringView.
This commit is contained in:
parent
c4d7be100e
commit
98666b012d
Notes:
sideshowbarker
2024-07-17 16:23:06 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/98666b012d Pull-request: https://github.com/SerenityOS/serenity/pull/20387
49
AK/URL.cpp
49
AK/URL.cpp
@ -86,19 +86,19 @@ void URL::set_scheme(DeprecatedString scheme)
|
||||
m_valid = compute_validity();
|
||||
}
|
||||
|
||||
void URL::set_username(DeprecatedString username, ApplyPercentEncoding apply_percent_encoding)
|
||||
// https://url.spec.whatwg.org/#set-the-username
|
||||
void URL::set_username(StringView username)
|
||||
{
|
||||
if (apply_percent_encoding == ApplyPercentEncoding::Yes)
|
||||
username = deprecated_string_percent_encode(username, PercentEncodeSet::Userinfo);
|
||||
m_username = move(username);
|
||||
// To set the username given a url and username, set url’s username to the result of running UTF-8 percent-encode on username using the userinfo percent-encode set.
|
||||
m_username = deprecated_string_percent_encode(username, PercentEncodeSet::Userinfo);
|
||||
m_valid = compute_validity();
|
||||
}
|
||||
|
||||
void URL::set_password(DeprecatedString password, ApplyPercentEncoding apply_percent_encoding)
|
||||
// https://url.spec.whatwg.org/#set-the-password
|
||||
void URL::set_password(StringView password)
|
||||
{
|
||||
if (apply_percent_encoding == ApplyPercentEncoding::Yes)
|
||||
password = deprecated_string_percent_encode(password, PercentEncodeSet::Userinfo);
|
||||
m_password = move(password);
|
||||
// To set the password given a url and password, set url’s password to the result of running UTF-8 percent-encode on password using the userinfo percent-encode set.
|
||||
m_password = deprecated_string_percent_encode(password, PercentEncodeSet::Userinfo);
|
||||
m_valid = compute_validity();
|
||||
}
|
||||
|
||||
@ -124,39 +124,28 @@ void URL::set_port(Optional<u16> port)
|
||||
m_valid = compute_validity();
|
||||
}
|
||||
|
||||
void URL::set_paths(Vector<DeprecatedString> paths, ApplyPercentEncoding apply_percent_encoding)
|
||||
void URL::set_paths(Vector<DeprecatedString> const& paths)
|
||||
{
|
||||
if (apply_percent_encoding == ApplyPercentEncoding::Yes) {
|
||||
Vector<DeprecatedString> encoded_paths;
|
||||
encoded_paths.ensure_capacity(paths.size());
|
||||
for (auto& segment : paths)
|
||||
encoded_paths.unchecked_append(deprecated_string_percent_encode(segment, PercentEncodeSet::Path));
|
||||
m_paths = move(encoded_paths);
|
||||
} else {
|
||||
m_paths = move(paths);
|
||||
}
|
||||
m_paths.clear_with_capacity();
|
||||
m_paths.ensure_capacity(paths.size());
|
||||
for (auto const& segment : paths)
|
||||
m_paths.unchecked_append(deprecated_string_percent_encode(segment, PercentEncodeSet::Path));
|
||||
m_valid = compute_validity();
|
||||
}
|
||||
|
||||
void URL::append_path(DeprecatedString path, ApplyPercentEncoding apply_percent_encoding)
|
||||
void URL::append_path(StringView path)
|
||||
{
|
||||
if (apply_percent_encoding == ApplyPercentEncoding::Yes)
|
||||
path = deprecated_string_percent_encode(path, PercentEncodeSet::Path);
|
||||
m_paths.append(path);
|
||||
m_paths.append(deprecated_string_percent_encode(path, PercentEncodeSet::Path));
|
||||
}
|
||||
|
||||
void URL::set_query(DeprecatedString query, ApplyPercentEncoding apply_percent_encoding)
|
||||
void URL::set_query(StringView query)
|
||||
{
|
||||
if (apply_percent_encoding == ApplyPercentEncoding::Yes)
|
||||
query = deprecated_string_percent_encode(query, is_special() ? PercentEncodeSet::SpecialQuery : PercentEncodeSet::Query);
|
||||
m_query = move(query);
|
||||
m_query = deprecated_string_percent_encode(query, is_special() ? PercentEncodeSet::SpecialQuery : PercentEncodeSet::Query);
|
||||
}
|
||||
|
||||
void URL::set_fragment(DeprecatedString fragment, ApplyPercentEncoding apply_percent_encoding)
|
||||
void URL::set_fragment(StringView fragment)
|
||||
{
|
||||
if (apply_percent_encoding == ApplyPercentEncoding::Yes)
|
||||
fragment = deprecated_string_percent_encode(fragment, PercentEncodeSet::Fragment);
|
||||
m_fragment = move(fragment);
|
||||
m_fragment = deprecated_string_percent_encode(fragment, PercentEncodeSet::Fragment);
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port
|
||||
|
16
AK/URL.h
16
AK/URL.h
@ -95,20 +95,16 @@ public:
|
||||
bool includes_credentials() const { return !m_username.is_empty() || !m_password.is_empty(); }
|
||||
bool is_special() const { return is_special_scheme(m_scheme); }
|
||||
|
||||
enum class ApplyPercentEncoding {
|
||||
Yes,
|
||||
No
|
||||
};
|
||||
void set_scheme(DeprecatedString);
|
||||
void set_username(DeprecatedString, ApplyPercentEncoding = ApplyPercentEncoding::Yes);
|
||||
void set_password(DeprecatedString, ApplyPercentEncoding = ApplyPercentEncoding::Yes);
|
||||
void set_username(StringView);
|
||||
void set_password(StringView);
|
||||
void set_host(Host);
|
||||
void set_port(Optional<u16>);
|
||||
void set_paths(Vector<DeprecatedString>, ApplyPercentEncoding = ApplyPercentEncoding::Yes);
|
||||
void set_query(DeprecatedString, ApplyPercentEncoding = ApplyPercentEncoding::Yes);
|
||||
void set_fragment(DeprecatedString fragment, ApplyPercentEncoding = ApplyPercentEncoding::Yes);
|
||||
void set_paths(Vector<DeprecatedString> const&);
|
||||
void set_query(StringView);
|
||||
void set_fragment(StringView fragment);
|
||||
void set_cannot_be_a_base_url(bool value) { m_cannot_be_a_base_url = value; }
|
||||
void append_path(DeprecatedString, ApplyPercentEncoding = ApplyPercentEncoding::Yes);
|
||||
void append_path(StringView);
|
||||
void append_slash()
|
||||
{
|
||||
// NOTE: To indicate that we want to end the path with a slash, we have to append an empty path segment.
|
||||
|
@ -506,7 +506,7 @@ WebIDL::ExceptionOr<Document*> Document::open(DeprecatedString const&, Deprecate
|
||||
auto new_url = entry_document.url();
|
||||
// 2. If entryDocument is not document, then set newURL's fragment to null.
|
||||
if (&entry_document != this)
|
||||
new_url.set_fragment("");
|
||||
new_url.set_fragment({});
|
||||
|
||||
// FIXME: 3. Run the URL and history update steps with document and newURL.
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ WebIDL::ExceptionOr<void> Location::set_hash(String const& value)
|
||||
auto input = value.bytes_as_string_view().trim("#"sv, TrimMode::Left);
|
||||
|
||||
// 5. Set copyURL's fragment to the empty string.
|
||||
copy_url.set_fragment("");
|
||||
copy_url.set_fragment(""sv);
|
||||
|
||||
// 6. Basic URL parse input, with copyURL as url and fragment state as state override.
|
||||
auto result_url = URLParser::basic_parse(input, {}, copy_url, URLParser::State::Fragment);
|
||||
|
@ -237,7 +237,7 @@ void URL::set_username(String const& username)
|
||||
return;
|
||||
|
||||
// 2. Set the username given this’s URL and the given value.
|
||||
m_url.set_username(username.to_deprecated_string(), AK::URL::ApplyPercentEncoding::Yes);
|
||||
m_url.set_username(username);
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#dom-url-password
|
||||
@ -257,7 +257,7 @@ void URL::set_password(String const& password)
|
||||
return;
|
||||
|
||||
// 2. Set the password given this’s URL and the given value.
|
||||
m_url.set_password(password.to_deprecated_string(), AK::URL::ApplyPercentEncoding::Yes);
|
||||
m_url.set_password(password);
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#dom-url-host
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
|
||||
WebIDL::ExceptionOr<String> to_json() const;
|
||||
|
||||
void set_query(Badge<URLSearchParams>, String query) { m_url.set_query(query.to_deprecated_string(), AK::URL::ApplyPercentEncoding::Yes); }
|
||||
void set_query(Badge<URLSearchParams>, StringView query) { m_url.set_query(query); }
|
||||
|
||||
private:
|
||||
URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);
|
||||
|
Loading…
Reference in New Issue
Block a user