From 66e1f8cdabc9b6e09a18ce3365304200197f6a90 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 8 Aug 2023 16:31:38 -0400 Subject: [PATCH] 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. --- AK/URLParser.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AK/URLParser.cpp b/AK/URLParser.cpp index 6b3c4cdc7ce..6707593091d 100644 --- a/AK/URLParser.cpp +++ b/AK/URLParser.cpp @@ -632,7 +632,9 @@ ErrorOr URLParser::serialize_host(URL::Host const& host) } // 3. Otherwise, host is a domain, opaque host, or empty host, return host. - return host.get(); + if (host.has()) + return host.get(); + return String {}; } // https://url.spec.whatwg.org/#start-with-a-windows-drive-letter