1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:17:44 +00: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:
Shannon Booth 2023-08-06 16:32:44 +12:00 committed by Andreas Kling
parent c4d7be100e
commit 98666b012d
6 changed files with 30 additions and 45 deletions

View file

@ -86,19 +86,19 @@ void URL::set_scheme(DeprecatedString scheme)
m_valid = compute_validity(); 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) // To set the username given a url and username, set urls username to the result of running UTF-8 percent-encode on username using the userinfo percent-encode set.
username = deprecated_string_percent_encode(username, PercentEncodeSet::Userinfo); m_username = deprecated_string_percent_encode(username, PercentEncodeSet::Userinfo);
m_username = move(username);
m_valid = compute_validity(); 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) // To set the password given a url and password, set urls password to the result of running UTF-8 percent-encode on password using the userinfo percent-encode set.
password = deprecated_string_percent_encode(password, PercentEncodeSet::Userinfo); m_password = deprecated_string_percent_encode(password, PercentEncodeSet::Userinfo);
m_password = move(password);
m_valid = compute_validity(); m_valid = compute_validity();
} }
@ -124,39 +124,28 @@ void URL::set_port(Optional<u16> port)
m_valid = compute_validity(); 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) { m_paths.clear_with_capacity();
Vector<DeprecatedString> encoded_paths; m_paths.ensure_capacity(paths.size());
encoded_paths.ensure_capacity(paths.size()); for (auto const& segment : paths)
for (auto& segment : paths) m_paths.unchecked_append(deprecated_string_percent_encode(segment, PercentEncodeSet::Path));
encoded_paths.unchecked_append(deprecated_string_percent_encode(segment, PercentEncodeSet::Path));
m_paths = move(encoded_paths);
} else {
m_paths = move(paths);
}
m_valid = compute_validity(); 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) m_paths.append(deprecated_string_percent_encode(path, PercentEncodeSet::Path));
path = deprecated_string_percent_encode(path, PercentEncodeSet::Path);
m_paths.append(path);
} }
void URL::set_query(DeprecatedString query, ApplyPercentEncoding apply_percent_encoding) void URL::set_query(StringView query)
{ {
if (apply_percent_encoding == ApplyPercentEncoding::Yes) m_query = deprecated_string_percent_encode(query, is_special() ? PercentEncodeSet::SpecialQuery : PercentEncodeSet::Query);
query = deprecated_string_percent_encode(query, is_special() ? PercentEncodeSet::SpecialQuery : PercentEncodeSet::Query);
m_query = move(query);
} }
void URL::set_fragment(DeprecatedString fragment, ApplyPercentEncoding apply_percent_encoding) void URL::set_fragment(StringView fragment)
{ {
if (apply_percent_encoding == ApplyPercentEncoding::Yes) m_fragment = deprecated_string_percent_encode(fragment, PercentEncodeSet::Fragment);
fragment = deprecated_string_percent_encode(fragment, PercentEncodeSet::Fragment);
m_fragment = move(fragment);
} }
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port // https://url.spec.whatwg.org/#cannot-have-a-username-password-port

View file

@ -95,20 +95,16 @@ public:
bool includes_credentials() const { return !m_username.is_empty() || !m_password.is_empty(); } bool includes_credentials() const { return !m_username.is_empty() || !m_password.is_empty(); }
bool is_special() const { return is_special_scheme(m_scheme); } bool is_special() const { return is_special_scheme(m_scheme); }
enum class ApplyPercentEncoding {
Yes,
No
};
void set_scheme(DeprecatedString); void set_scheme(DeprecatedString);
void set_username(DeprecatedString, ApplyPercentEncoding = ApplyPercentEncoding::Yes); void set_username(StringView);
void set_password(DeprecatedString, ApplyPercentEncoding = ApplyPercentEncoding::Yes); void set_password(StringView);
void set_host(Host); void set_host(Host);
void set_port(Optional<u16>); void set_port(Optional<u16>);
void set_paths(Vector<DeprecatedString>, ApplyPercentEncoding = ApplyPercentEncoding::Yes); void set_paths(Vector<DeprecatedString> const&);
void set_query(DeprecatedString, ApplyPercentEncoding = ApplyPercentEncoding::Yes); void set_query(StringView);
void set_fragment(DeprecatedString fragment, ApplyPercentEncoding = ApplyPercentEncoding::Yes); void set_fragment(StringView fragment);
void set_cannot_be_a_base_url(bool value) { m_cannot_be_a_base_url = value; } 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() void append_slash()
{ {
// NOTE: To indicate that we want to end the path with a slash, we have to append an empty path segment. // NOTE: To indicate that we want to end the path with a slash, we have to append an empty path segment.

View file

@ -506,7 +506,7 @@ WebIDL::ExceptionOr<Document*> Document::open(DeprecatedString const&, Deprecate
auto new_url = entry_document.url(); auto new_url = entry_document.url();
// 2. If entryDocument is not document, then set newURL's fragment to null. // 2. If entryDocument is not document, then set newURL's fragment to null.
if (&entry_document != this) 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. // FIXME: 3. Run the URL and history update steps with document and newURL.
} }

View file

@ -309,7 +309,7 @@ WebIDL::ExceptionOr<void> Location::set_hash(String const& value)
auto input = value.bytes_as_string_view().trim("#"sv, TrimMode::Left); auto input = value.bytes_as_string_view().trim("#"sv, TrimMode::Left);
// 5. Set copyURL's fragment to the empty string. // 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. // 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); auto result_url = URLParser::basic_parse(input, {}, copy_url, URLParser::State::Fragment);

View file

@ -237,7 +237,7 @@ void URL::set_username(String const& username)
return; return;
// 2. Set the username given thiss URL and the given value. // 2. Set the username given thiss 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 // https://url.spec.whatwg.org/#dom-url-password
@ -257,7 +257,7 @@ void URL::set_password(String const& password)
return; return;
// 2. Set the password given thiss URL and the given value. // 2. Set the password given thiss 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 // https://url.spec.whatwg.org/#dom-url-host

View file

@ -65,7 +65,7 @@ public:
WebIDL::ExceptionOr<String> to_json() const; 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: private:
URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query); URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);