mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-25 20:22:18 +03:00
AK: Implement 'concept-host-serializer' in URL spec
This implementation will allow us to fix serialization of IPv6 addresses not being surrounded by '[' and ']'. Nothing is calling this function yet - this will come in the next (larger) commit where the underlying host representation inside of AK::URL is changed from DeprecatedString to URL::Host.
This commit is contained in:
parent
803ca8cc80
commit
768f070b86
Notes:
sideshowbarker
2024-07-18 00:41:35 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/768f070b86 Pull-request: https://github.com/SerenityOS/serenity/pull/20245 Reviewed-by: https://github.com/kennethmyhra ✅
@ -609,6 +609,26 @@ static Optional<DeprecatedString> parse_host(StringView input, bool is_not_speci
|
||||
return ascii_domain;
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#concept-host-serializer
|
||||
ErrorOr<String> URLParser::serialize_host(URL::Host const& host)
|
||||
{
|
||||
// 1. If host is an IPv4 address, return the result of running the IPv4 serializer on host.
|
||||
if (host.has<URL::IPv4Address>())
|
||||
return serialize_ipv4_address(host.get<URL::IPv4Address>());
|
||||
|
||||
// 2. Otherwise, if host is an IPv6 address, return U+005B ([), followed by the result of running the IPv6 serializer on host, followed by U+005D (]).
|
||||
if (host.has<URL::IPv6Address>()) {
|
||||
StringBuilder output;
|
||||
TRY(output.try_append('['));
|
||||
serialize_ipv6_address(host.get<URL::IPv6Address>(), output);
|
||||
TRY(output.try_append(']'));
|
||||
return output.to_string();
|
||||
}
|
||||
|
||||
// 3. Otherwise, host is a domain, opaque host, or empty host, return host.
|
||||
return host.get<String>();
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#start-with-a-windows-drive-letter
|
||||
constexpr bool starts_with_windows_drive_letter(StringView input)
|
||||
{
|
||||
|
@ -61,6 +61,9 @@ public:
|
||||
// https://url.spec.whatwg.org/#string-percent-encode-after-encoding
|
||||
static DeprecatedString percent_encode_after_encoding(StringView input, URL::PercentEncodeSet percent_encode_set, bool space_as_plus = false);
|
||||
|
||||
// https://url.spec.whatwg.org/#concept-host-serializer
|
||||
static ErrorOr<String> serialize_host(URL::Host const&);
|
||||
|
||||
private:
|
||||
static Optional<URL> parse_data_url(StringView raw_input);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user