mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:57:45 +00:00
AK: Recompute URL validity after changing protocol/host/path
This allows you to build URLs by calling setters on an empty URL and actually get a valid URL at the end.
This commit is contained in:
parent
827e375297
commit
b1555381ee
2 changed files with 43 additions and 4 deletions
38
AK/URL.cpp
38
AK/URL.cpp
|
@ -210,4 +210,42 @@ URL URL::complete_url(const String& string) const
|
|||
return url;
|
||||
}
|
||||
|
||||
void URL::set_protocol(const String& protocol)
|
||||
{
|
||||
m_protocol = protocol;
|
||||
m_valid = compute_validity();
|
||||
}
|
||||
|
||||
void URL::set_host(const String& host)
|
||||
{
|
||||
m_host = host;
|
||||
m_valid = compute_validity();
|
||||
}
|
||||
|
||||
void URL::set_path(const String& path)
|
||||
{
|
||||
m_path = path;
|
||||
m_valid = compute_validity();
|
||||
}
|
||||
|
||||
void URL::set_query(const String& query)
|
||||
{
|
||||
m_query = query;
|
||||
}
|
||||
|
||||
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_path.is_empty())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue