AK: Move URL::cannot_have_a_username_or_password_or_port out of line

This doesn't seem trivial enough to be defining in the header like this,
and should not be a performance critical function anyhow.

Also add spec comments while we are at it, and a FIXME since we do not
seem to exactly align.
This commit is contained in:
Shannon Booth 2023-07-26 20:54:36 +12:00 committed by Andreas Kling
parent 0c0117fc86
commit a1ae701a7d
Notes: sideshowbarker 2024-07-18 03:23:00 +09:00
2 changed files with 9 additions and 1 deletions

View File

@ -152,6 +152,14 @@ void URL::set_fragment(DeprecatedString fragment, ApplyPercentEncoding apply_per
m_fragment = move(fragment);
}
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port
bool URL::cannot_have_a_username_or_password_or_port() const
{
// A URL cannot have a username/password/port if its host is null or the empty string, or its scheme is "file".
// FIXME: The spec does not mention anything to do with 'cannot be a base URL'.
return m_host.is_null() || m_host.is_empty() || m_cannot_be_a_base_url || m_scheme == "file"sv;
}
// FIXME: This is by no means complete.
// NOTE: This relies on some assumptions about how the spec-defined URL parser works that may turn out to be wrong.
bool URL::compute_validity() const

View File

@ -89,7 +89,7 @@ public:
u16 port_or_default() const { return m_port.value_or(default_port_for_scheme(m_scheme)); }
bool cannot_be_a_base_url() const { return m_cannot_be_a_base_url; }
bool cannot_have_a_username_or_password_or_port() const { return m_host.is_null() || m_host.is_empty() || m_cannot_be_a_base_url || m_scheme == "file"sv; }
bool cannot_have_a_username_or_password_or_port() const;
bool includes_credentials() const { return !m_username.is_empty() || !m_password.is_empty(); }
bool is_special() const { return is_special_scheme(m_scheme); }