1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 11:07:35 +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

@ -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>();
}