From a1ae701a7db69bbd30fe20983052746072a36152 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 26 Jul 2023 20:54:36 +1200 Subject: [PATCH] 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. --- AK/URL.cpp | 8 ++++++++ AK/URL.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/AK/URL.cpp b/AK/URL.cpp index eceb96d34b..1770a9e9d9 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -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 diff --git a/AK/URL.h b/AK/URL.h index 98955b2ef6..c5dd2b2c4d 100644 --- a/AK/URL.h +++ b/AK/URL.h @@ -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); }