mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
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:
parent
768f070b86
commit
8751be09f9
36 changed files with 175 additions and 143 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/URLParser.h>
|
||||
#include <LibWeb/HTML/WorkerGlobalScope.h>
|
||||
#include <LibWeb/HTML/WorkerLocation.h>
|
||||
|
||||
|
@ -43,15 +44,15 @@ WebIDL::ExceptionOr<String> WorkerLocation::host() const
|
|||
auto const& url = m_global_scope->url();
|
||||
|
||||
// 2. If url's host is null, return the empty string.
|
||||
if (url.host().is_empty())
|
||||
if (url.host().has<Empty>())
|
||||
return String {};
|
||||
|
||||
// 3. If url's port is null, return url's host, serialized.
|
||||
if (!url.port().has_value())
|
||||
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(url.host()));
|
||||
return TRY_OR_THROW_OOM(vm, url.serialized_host());
|
||||
|
||||
// 4. Return url's host, serialized, followed by ":" and url's port, serialized.
|
||||
return TRY_OR_THROW_OOM(vm, String::formatted("{}:{}", url.host().view(), url.port().value()));
|
||||
return TRY_OR_THROW_OOM(vm, String::formatted("{}:{}", TRY_OR_THROW_OOM(vm, url.serialized_host()), url.port().value()));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-hostname
|
||||
|
@ -64,11 +65,11 @@ WebIDL::ExceptionOr<String> WorkerLocation::hostname() const
|
|||
auto const& host = m_global_scope->url().host();
|
||||
|
||||
// 2. If host is null, return the empty string.
|
||||
if (host.is_empty())
|
||||
if (host.has<Empty>())
|
||||
return String {};
|
||||
|
||||
// 3. Return host, serialized.
|
||||
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(host));
|
||||
return TRY_OR_THROW_OOM(vm, URLParser::serialize_host(host));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-port
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue