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.
This commit is contained in:
Sergey Bugaev 2020-04-19 11:36:56 +03:00 committed by Andreas Kling
parent 50c139e61c
commit 5a96a6565b

View file

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