Skip to content

Commit

Permalink
LibURL: Convert ASCII only URLs to lowercase during parsing
Browse files Browse the repository at this point in the history
This fixes an issue where entering EXAMPLE.COM into the URL bar in the
browser would fail to load as expected.
  • Loading branch information
tcl3 authored and trflynn89 committed Jun 11, 2024
1 parent fd98076 commit 1a4b042
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Tests/LibURL/TestURL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
4 changes: 3 additions & 1 deletion Userland/Libraries/LibURL/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1a4b042

Please sign in to comment.