AK: Support serializing opaque hosts

The spec indicates we should support serializing opaque hosts, but we
were assuming the host contained a String. Opaque hosts are represented
with Empty. Return an empty string here instead to prevent crashing on
an invalid variant access.
This commit is contained in:
Timothy Flynn 2023-08-08 16:31:38 -04:00 committed by Andreas Kling
parent dcfec8bfbe
commit 66e1f8cdab
Notes: sideshowbarker 2024-07-16 22:51:10 +09:00

View file

@ -632,7 +632,9 @@ ErrorOr<String> URLParser::serialize_host(URL::Host const& host)
}
// 3. Otherwise, host is a domain, opaque host, or empty host, return host.
return host.get<String>();
if (host.has<String>())
return host.get<String>();
return String {};
}
// https://url.spec.whatwg.org/#start-with-a-windows-drive-letter