From 5a96a6565b194ae8323b35db5e3afb64acc8bc80 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sun, 19 Apr 2020 11:36:56 +0300 Subject: [PATCH] AK: Consider more URLs invalid Not just http or https. This fixes "foo" being recognized as a valid URL with protocol "foo", empty host and empty path. --- AK/URL.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/AK/URL.cpp b/AK/URL.cpp index 329f13f07ca..d029282b959 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -169,6 +169,8 @@ bool URL::parse(const StringView& string) m_host = String::copy(buffer); m_path = "/"; } + if (state == State::InProtocol) + return false; if (state == State::InPath) m_path = String::copy(buffer); if (state == State::InQuery) @@ -277,12 +279,12 @@ bool URL::compute_validity() const // FIXME: This is by no means complete. if (m_protocol.is_empty()) return false; - if (m_protocol == "http" || m_protocol == "https") { - if (m_host.is_empty()) - return false; - } else if (m_protocol == "file") { + if (m_protocol == "file") { if (m_path.is_empty()) return false; + } else { + if (m_host.is_empty()) + return false; } return true; }