1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:38:11 +00:00

AK: Implement IPV4 host URL parsing to specification

This implements both the parsing and serialization IPV4 parts from
the URL spec.
This commit is contained in:
Shannon Booth 2023-07-23 21:09:29 +12:00 committed by Tim Flynn
parent 50359567e0
commit 8d2ccf0f4f
2 changed files with 239 additions and 7 deletions

View file

@ -458,3 +458,40 @@ TEST_CASE(ipv6_address)
EXPECT_EQ(url.is_valid(), false);
}
}
TEST_CASE(ipv4_address)
{
{
constexpr auto ipv4_url = "http://127.0.0.1/index.html"sv;
URL url(ipv4_url);
EXPECT(url.is_valid());
EXPECT_EQ(url.host(), "127.0.0.1"sv);
}
{
constexpr auto ipv4_url = "http://0x.0x.0"sv;
URL url(ipv4_url);
EXPECT(url.is_valid());
EXPECT_EQ(url.host(), "0.0.0.0"sv);
}
{
constexpr auto bad_ipv4_url = "https://127..0.0.1"sv;
URL url(bad_ipv4_url);
EXPECT(!url.is_valid());
}
{
constexpr auto ipv4_url = "http://256"sv;
URL url(ipv4_url);
EXPECT(url.is_valid());
EXPECT_EQ(url.host(), "0.0.1.0"sv);
}
{
constexpr auto ipv4_url = "http://888888888"sv;
URL url(ipv4_url);
EXPECT(url.is_valid());
EXPECT_EQ(url.host(), "52.251.94.56"sv);
}
}