LibURL: Convert ASCII only URLs to lowercase during parsing

This fixes an issue where entering EXAMPLE.COM into the URL bar in the
browser would fail to load as expected.
This commit is contained in:
Tim Ledbetter 2024-06-10 09:22:56 +01:00 committed by Tim Flynn
parent fd98076aca
commit 1a4b042664
Notes: sideshowbarker 2024-07-17 06:40:35 +09:00
2 changed files with 24 additions and 1 deletions

View file

@ -489,3 +489,24 @@ TEST_CASE(username_and_password)
EXPECT_EQ(MUST(url.password()), password);
}
}
TEST_CASE(ascii_only_url)
{
{
constexpr auto upper_case_url = "HTTP://EXAMPLE.COM:80/INDEX.HTML#FRAGMENT"sv;
URL::URL url(upper_case_url);
EXPECT(url.is_valid());
EXPECT_EQ(url.scheme(), "http");
EXPECT_EQ(MUST(url.serialized_host()), "example.com"sv);
EXPECT_EQ(url.to_byte_string(), "http://example.com/INDEX.HTML#FRAGMENT");
}
{
constexpr auto mixed_case_url = "hTtP://eXaMpLe.CoM:80/iNdEx.HtMl#fRaGmEnT"sv;
URL::URL url(mixed_case_url);
EXPECT(url.is_valid());
EXPECT_EQ(url.scheme(), "http");
EXPECT_EQ(MUST(url.serialized_host()), "example.com"sv);
EXPECT_EQ(url.to_byte_string(), "http://example.com/iNdEx.HtMl#fRaGmEnT");
}
}

View file

@ -586,7 +586,9 @@ static ErrorOr<String> domain_to_ascii(StringView domain, bool be_strict)
// 3. If result is the empty string, domain-to-ASCII validation error, return failure.
if (domain.is_empty())
return Error::from_string_literal("Empty domain");
return String::from_utf8_without_validation(domain.bytes());
auto lowercase_domain = domain.to_lowercase_string();
return String::from_utf8_without_validation(lowercase_domain.bytes());
}
Unicode::IDNA::ToAsciiOptions const options {