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
Notes: sideshowbarker 2024-07-17 05:01:22 +09:00
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();
}
}

View file

@ -72,5 +72,6 @@ private:
};
HTML::Origin url_origin(AK::URL const&);
bool host_is_domain(StringView host);
}