mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Rewrite URL::compute_validity() to conform to new parser
This rewrites the URL validation check to be more specific, so it can more accurately detect if a user of URL class constructs invalid URLs by hand.
This commit is contained in:
parent
522ef53b98
commit
ebf074ca29
Notes:
sideshowbarker
2024-07-18 17:03:55 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/ebf074ca298 Pull-request: https://github.com/SerenityOS/serenity/pull/7478 Reviewed-by: https://github.com/awesomekling
1 changed files with 23 additions and 15 deletions
38
AK/URL.cpp
38
AK/URL.cpp
|
@ -116,31 +116,39 @@ void URL::set_fragment(const String& fragment)
|
|||
m_fragment = fragment;
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
// FIXME: This is by no means complete.
|
||||
if (m_scheme.is_empty())
|
||||
return false;
|
||||
|
||||
if (m_scheme == "about") {
|
||||
if (path().is_empty())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_scheme == "file") {
|
||||
if (path().is_empty())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_scheme == "data") {
|
||||
if (m_data_mime_type.is_empty())
|
||||
return false;
|
||||
return true;
|
||||
if (m_data_payload_is_base64) {
|
||||
if (m_data_payload.length() % 4 != 0)
|
||||
return false;
|
||||
for (auto character : m_data_payload) {
|
||||
if (!is_ascii_alphanumeric(character) || character == '+' || character == '/' || character == '=')
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (m_cannot_be_a_base_url) {
|
||||
if (m_paths.size() != 1)
|
||||
return false;
|
||||
if (m_paths[0].is_empty())
|
||||
return false;
|
||||
} else {
|
||||
if (m_scheme.is_one_of("about", "mailto"))
|
||||
return false;
|
||||
// NOTE: Maybe it is allowed to have a zero-segment path.
|
||||
if (m_paths.size() == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_host.is_empty())
|
||||
// NOTE: A file URL's host should be the empty string for localhost, not null.
|
||||
if (m_scheme == "file" && m_host.is_null())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue