1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

LibURL: Correctly acquire the registrable domain for a URL

We were using the public suffix of the URL's host as its registrable
domain. But the registrable domain is actually the public suffix plus
one additional label.
This commit is contained in:
Timothy Flynn 2025-03-09 11:11:35 -04:00 committed by Jelle Raaijmakers
parent d0f80e1f05
commit a34f7a5bd1
Notes: github-actions[bot] 2025-03-11 11:11:58 +00:00
4 changed files with 75 additions and 1 deletions

View file

@ -558,3 +558,52 @@ TEST_CASE(invalid_domain_code_points)
EXPECT(!url.has_value());
}
}
TEST_CASE(get_registrable_domain)
{
{
auto domain = URL::get_registrable_domain({});
EXPECT(!domain.has_value());
}
{
auto domain = URL::get_registrable_domain("foobar"sv);
EXPECT(!domain.has_value());
}
{
auto domain = URL::get_registrable_domain("com"sv);
EXPECT(!domain.has_value());
}
{
auto domain = URL::get_registrable_domain(".com"sv);
EXPECT(!domain.has_value());
}
{
auto domain = URL::get_registrable_domain("example.com"sv);
VERIFY(domain.has_value());
EXPECT_EQ(*domain, "example.com"sv);
}
{
auto domain = URL::get_registrable_domain(".example.com"sv);
VERIFY(domain.has_value());
EXPECT_EQ(*domain, "example.com"sv);
}
{
auto domain = URL::get_registrable_domain("www.example.com"sv);
VERIFY(domain.has_value());
EXPECT_EQ(*domain, "example.com"sv);
}
{
auto domain = URL::get_registrable_domain("sub.www.example.com"sv);
VERIFY(domain.has_value());
EXPECT_EQ(*domain, "example.com"sv);
}
{
auto domain = URL::get_registrable_domain("github.io"sv);
EXPECT(!domain.has_value());
}
{
auto domain = URL::get_registrable_domain("ladybird.github.io"sv);
VERIFY(domain.has_value());
EXPECT_EQ(*domain, "ladybird.github.io"sv);
}
}