mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
LibWeb: Implement 'host is domain' concept from the URL spec
This commit is contained in:
parent
55315d72f7
commit
7fd4c7b0c6
2 changed files with 12 additions and 0 deletions
|
@ -5,6 +5,8 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/IPv4Address.h>
|
||||||
|
#include <AK/IPv6Address.h>
|
||||||
#include <AK/URLParser.h>
|
#include <AK/URLParser.h>
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
#include <LibWeb/URL/URL.h>
|
#include <LibWeb/URL/URL.h>
|
||||||
|
@ -340,4 +342,13 @@ HTML::Origin url_origin(AK::URL const& url)
|
||||||
return HTML::Origin {};
|
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&);
|
HTML::Origin url_origin(AK::URL const&);
|
||||||
|
bool host_is_domain(StringView host);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue