mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
LibWeb: Implement 'host is domain' concept from the URL spec
This commit is contained in:
parent
55315d72f7
commit
7fd4c7b0c6
Notes:
sideshowbarker
2024-07-17 05:01:22 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/7fd4c7b0c6 Pull-request: https://github.com/SerenityOS/serenity/pull/15795 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/davidot ✅
2 changed files with 12 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -72,5 +72,6 @@ private:
|
|||
};
|
||||
|
||||
HTML::Origin url_origin(AK::URL const&);
|
||||
bool host_is_domain(StringView host);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue