LibWeb: Port Document encoding_parse_url and parse_url to Optional<URL>

This ports two more APIs away from URL::is_valid.
This commit is contained in:
Shannon Booth 2025-01-23 19:40:57 +13:00 committed by Tim Ledbetter
commit 22a7cd9700
Notes: github-actions[bot] 2025-01-27 00:04:07 +00:00
26 changed files with 135 additions and 107 deletions

View file

@ -466,10 +466,15 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
if (!matches_link_pseudo_class(element))
return false;
auto document_url = element.document().url();
URL::URL target_url = element.document().encoding_parse_url(element.attribute(HTML::AttributeNames::href).value_or({}));
if (target_url.fragment().has_value())
return document_url.equals(target_url, URL::ExcludeFragment::No);
return document_url.equals(target_url, URL::ExcludeFragment::Yes);
auto maybe_href = element.attribute(HTML::AttributeNames::href);
if (!maybe_href.has_value())
return false;
auto target_url = element.document().encoding_parse_url(*maybe_href);
if (!target_url.has_value())
return false;
if (target_url->fragment().has_value())
return document_url.equals(*target_url, URL::ExcludeFragment::No);
return document_url.equals(*target_url, URL::ExcludeFragment::Yes);
}
case CSS::PseudoClass::Visited:
// FIXME: Maybe match this selector sometimes?