LibURL: Correct logic for domains not matched by PSL in public_suffix
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

For the AO defined in the URL specification, in the case the
domain does not match against the PSL, we should be returning
the TLD. This fixes a crash for a bunch of WPT tests using the
Document.domain setter when the test is being served by WPT
locally.

We should be doing similar logic in registrable_domain, but that
unfortunately runs into some other issues, so just leave a FIXME
for now.
This commit is contained in:
Shannon Booth 2025-06-28 22:19:33 +12:00 committed by Tim Ledbetter
commit b49b1b35e4
Notes: github-actions[bot] 2025-06-29 11:49:06 +00:00
2 changed files with 60 additions and 7 deletions

View file

@ -641,3 +641,51 @@ TEST_CASE(get_registrable_domain)
EXPECT_EQ(*domain, "ladybird.github.io"sv);
}
}
TEST_CASE(public_suffix)
{
{
auto domain = URL::Parser::parse_host("com"sv);
EXPECT_EQ(domain->public_suffix(), "com"sv);
}
{
auto domain = URL::Parser::parse_host("example.com"sv);
EXPECT_EQ(domain->public_suffix(), "com"sv);
}
{
auto domain = URL::Parser::parse_host("www.example.com"sv);
EXPECT_EQ(domain->public_suffix(), "com"sv);
}
{
auto domain = URL::Parser::parse_host("EXAMPLE.COM"sv);
EXPECT_EQ(domain->public_suffix(), "com"sv);
}
{
auto domain = URL::Parser::parse_host("www.example.com."sv);
EXPECT_EQ(domain->public_suffix(), "com."sv);
}
{
auto domain = URL::Parser::parse_host("github.io"sv);
EXPECT_EQ(domain->public_suffix(), "github.io"sv);
}
{
auto domain = URL::Parser::parse_host("whatwg.github.io"sv);
EXPECT_EQ(domain->public_suffix(), "github.io"sv);
}
{
auto domain = URL::Parser::parse_host("إختبار"sv);
EXPECT_EQ(domain->public_suffix(), "xn--kgbechtv"sv);
}
{
auto domain = URL::Parser::parse_host("example.إختبار"sv);
EXPECT_EQ(domain->public_suffix(), "xn--kgbechtv"sv);
}
{
auto domain = URL::Parser::parse_host("sub.example.إختبار"sv);
EXPECT_EQ(domain->public_suffix(), "xn--kgbechtv"sv);
}
{
auto domain = URL::Parser::parse_host("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"sv);
EXPECT_EQ(domain->public_suffix(), OptionalNone {});
}
}