AK: Serialize URL hosts with 'concept-host-serializer'

In order to follow spec text to achieve this, we need to change the
underlying representation of a host in AK::URL to deserialized format.
Before this, we were parsing the host and then immediately serializing
it again.

Making that change resulted in a whole bunch of fallout.

After this change, callers can access the serialized data through
this concept-host-serializer. The functional end result of this
change is that IPv6 hosts are now correctly serialized to be
surrounded with '[' and ']'.
This commit is contained in:
Shannon Booth 2023-07-27 21:40:41 +12:00 committed by Andreas Kling
parent 768f070b86
commit 8751be09f9
Notes: sideshowbarker 2024-07-18 02:13:10 +09:00
36 changed files with 175 additions and 143 deletions

View file

@ -167,15 +167,15 @@ DeprecatedString HTMLHyperlinkElementUtils::host() const
auto& url = m_url;
// 3. If url or url's host is null, return the empty string.
if (!url.has_value() || url->host().is_null())
if (!url.has_value() || url->host().has<Empty>())
return DeprecatedString::empty();
// 4. If url's port is null, return url's host, serialized.
if (!url->port().has_value())
return url->host();
return url->serialized_host().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
// 5. Return url's host, serialized, followed by ":" and url's port, serialized.
return DeprecatedString::formatted("{}:{}", url->host(), url->port().value());
return DeprecatedString::formatted("{}:{}", url->serialized_host().release_value_but_fixme_should_propagate_errors(), url->port().value());
}
// https://html.spec.whatwg.org/multipage/links.html#dom-hyperlink-host
@ -205,11 +205,14 @@ DeprecatedString HTMLHyperlinkElementUtils::hostname() const
// 1. Reinitialize url.
//
// 2. Let url be this element's url.
//
AK::URL url(href());
// 3. If url or url's host is null, return the empty string.
//
if (url.host().has<Empty>())
return DeprecatedString::empty();
// 4. Return url's host, serialized.
return AK::URL(href()).host();
return url.serialized_host().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
}
void HTMLHyperlinkElementUtils::set_hostname(DeprecatedString hostname)