summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-10-13 18:26:35 +0200
committerLinus Groh <mail@linusgroh.de>2022-10-30 20:10:29 +0000
commit7fd4c7b0c67d343f66471553a097d4f962418426 (patch)
treefa21277e6a3d221fd1ca2b7309cf479b8d1f177e
parent55315d72f7382f57368b8d6126a2ff7cd237fbe8 (diff)
downloadserenity-7fd4c7b0c67d343f66471553a097d4f962418426.zip
LibWeb: Implement 'host is domain' concept from the URL spec
-rw-r--r--Userland/Libraries/LibWeb/URL/URL.cpp11
-rw-r--r--Userland/Libraries/LibWeb/URL/URL.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/URL/URL.cpp b/Userland/Libraries/LibWeb/URL/URL.cpp
index 09bb522f9e..57944b664e 100644
--- a/Userland/Libraries/LibWeb/URL/URL.cpp
+++ b/Userland/Libraries/LibWeb/URL/URL.cpp
@@ -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();
+}
+
}
diff --git a/Userland/Libraries/LibWeb/URL/URL.h b/Userland/Libraries/LibWeb/URL/URL.h
index 44d5add4fd..e2af21fa3e 100644
--- a/Userland/Libraries/LibWeb/URL/URL.h
+++ b/Userland/Libraries/LibWeb/URL/URL.h
@@ -72,5 +72,6 @@ private:
};
HTML::Origin url_origin(AK::URL const&);
+bool host_is_domain(StringView host);
}