1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

LibWeb: Implement 'host is domain' concept from the URL spec

This commit is contained in:
Linus Groh 2022-10-13 18:26:35 +02:00
parent 55315d72f7
commit 7fd4c7b0c6
2 changed files with 12 additions and 0 deletions

View file

@ -5,6 +5,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/IPv4Address.h>
#include <AK/IPv6Address.h>
#include <AK/URLParser.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/URL/URL.h>
@ -340,4 +342,13 @@ HTML::Origin url_origin(AK::URL const& url)
return HTML::Origin {};
}
// https://url.spec.whatwg.org/#concept-domain
bool host_is_domain(StringView host)
{
// A domain is a non-empty ASCII string that identifies a realm within a network.
return !host.is_empty()
&& !IPv4Address::from_string(host).has_value()
&& !IPv6Address::from_string(host).has_value();
}
}