1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:07:34 +00:00

AK: Port URL username/password from DeprecatedString to String

And for cases that just need to check whether the password/username is
empty, add a raw_{password,username} helper to avoid any allocation.
This commit is contained in:
Shannon Booth 2023-08-12 16:52:38 +12:00 committed by Andrew Kaster
parent 6b29dc3e46
commit 55a01e72ca
11 changed files with 44 additions and 39 deletions

View file

@ -1455,7 +1455,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
// true, set authorizationValue to httpRequests current URL, converted to an `Authorization` value.
else if (http_request->current_url().includes_credentials() && is_authentication_fetch == IsAuthenticationFetch::Yes) {
auto const& url = http_request->current_url();
auto payload = TRY_OR_THROW_OOM(vm, String::formatted("{}:{}", url.username(), url.password()));
auto payload = MUST(String::formatted("{}:{}", MUST(url.username()), MUST(url.password())));
authorization_value = TRY_OR_THROW_OOM(vm, encode_base64(payload.bytes()));
}
@ -1612,10 +1612,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
auto password = DeprecatedString::empty();
// 3. Set the username given requests current URL and username.
request->current_url().set_username(move(username));
MUST(request->current_url().set_username(username));
// 4. Set the password given requests current URL and password.
request->current_url().set_password(move(password));
MUST(request->current_url().set_password(password));
}
// 4. Set response to the result of running HTTP-network-or-cache fetch given fetchParams and true.

View file

@ -42,8 +42,8 @@ static bool url_matches_about_blank(AK::URL const& url)
// A URL matches about:blank if its scheme is "about", its path contains a single string "blank", its username and password are the empty string, and its host is null.
return url.scheme() == "about"sv
&& url.serialize_path() == "blank"sv
&& url.username().is_empty()
&& url.password().is_empty()
&& url.raw_username().is_empty()
&& url.raw_password().is_empty()
&& url.host().has<Empty>();
}

View file

@ -97,7 +97,7 @@ DeprecatedString HTMLHyperlinkElementUtils::username() const
return DeprecatedString::empty();
// 3. Return this element's url's username.
return m_url->username();
return m_url->username().release_value().to_deprecated_string();
}
// https://html.spec.whatwg.org/multipage/links.html#dom-hyperlink-username
@ -114,7 +114,7 @@ void HTMLHyperlinkElementUtils::set_username(DeprecatedString username)
return;
// 4. Set the username given thiss URL and the given value.
url->set_username(username);
MUST(url->set_username(username));
// 5. Update href.
update_href();
@ -134,7 +134,7 @@ DeprecatedString HTMLHyperlinkElementUtils::password() const
return DeprecatedString::empty();
// 4. Return url's password.
return url->password();
return url->password().release_value().to_deprecated_string();
}
// https://html.spec.whatwg.org/multipage/links.html#dom-hyperlink-password
@ -151,7 +151,7 @@ void HTMLHyperlinkElementUtils::set_password(DeprecatedString password)
return;
// 4. Set the password, given url and the given value.
url->set_password(move(password));
MUST(url->set_password(password));
// 5. Update href.
update_href();

View file

@ -215,8 +215,8 @@ static bool url_matches_about_blank(AK::URL const& url)
// A URL matches about:blank if its scheme is "about", its path contains a single string "blank", its username and password are the empty string, and its host is null.
return url.scheme() == "about"sv
&& url.serialize_path() == "blank"sv
&& url.username().is_empty()
&& url.password().is_empty()
&& url.raw_username().is_empty()
&& url.raw_password().is_empty()
&& url.host().has<Empty>();
}

View file

@ -175,10 +175,10 @@ Optional<AK::URL> strip_url_for_use_as_referrer(Optional<AK::URL> url, OriginOnl
return {};
// 3. Set urls username to the empty string.
url->set_username(""sv);
MUST(url->set_username(""sv));
// 4. Set urls password to the empty string.
url->set_password(""sv);
MUST(url->set_password(""sv));
// 5. Set urls fragment to null.
url->set_fragment({});

View file

@ -224,7 +224,7 @@ WebIDL::ExceptionOr<String> URL::username() const
auto& vm = realm().vm();
// The username getter steps are to return thiss URLs username.
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_url.username()));
return TRY_OR_THROW_OOM(vm, m_url.username());
}
// https://url.spec.whatwg.org/#ref-for-dom-url-username%E2%91%A0
@ -235,7 +235,7 @@ void URL::set_username(String const& username)
return;
// 2. Set the username given thiss URL and the given value.
m_url.set_username(username);
MUST(m_url.set_username(username));
}
// https://url.spec.whatwg.org/#dom-url-password
@ -244,7 +244,7 @@ WebIDL::ExceptionOr<String> URL::password() const
auto& vm = realm().vm();
// The password getter steps are to return thiss URLs password.
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_url.password()));
return TRY_OR_THROW_OOM(vm, m_url.password());
}
// https://url.spec.whatwg.org/#ref-for-dom-url-password%E2%91%A0
@ -255,7 +255,7 @@ void URL::set_password(String const& password)
return;
// 2. Set the password given thiss URL and the given value.
m_url.set_password(password);
MUST(m_url.set_password(password));
}
// https://url.spec.whatwg.org/#dom-url-host

View file

@ -389,10 +389,10 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
if (!parsed_url.host().has<Empty>()) {
// 1. If the username argument is not null, set the username given parsedURL and username.
if (username.has_value())
parsed_url.set_username(username.value().to_deprecated_string());
MUST(parsed_url.set_username(username.value()));
// 2. If the password argument is not null, set the password given parsedURL and password.
if (password.has_value())
parsed_url.set_password(password.value().to_deprecated_string());
MUST(parsed_url.set_password(password.value()));
}
// 9. If async is false, the current global object is a Window object, and either thiss timeout is