AK: Unbreak parsing of file:// URLs with no host

We should still accept file:/// in the URL parser. :^)
This commit is contained in:
Andreas Kling 2020-05-09 16:47:05 +02:00
parent 27d1e7f432
commit 3422019e35
Notes: sideshowbarker 2024-07-19 06:48:31 +09:00
2 changed files with 25 additions and 1 deletions

View file

@ -130,4 +130,22 @@ TEST_CASE(serialization)
EXPECT_EQ(URL("https://www.serenityos.org:443/foo/bar.html?query#fragment").to_string(), "https://www.serenityos.org/foo/bar.html?query#fragment");
}
TEST_CASE(file_url_with_hostname)
{
URL url("file://localhost/my/file");
EXPECT_EQ(url.is_valid(), true);
EXPECT_EQ(url.host(), "localhost");
EXPECT_EQ(url.path(), "/my/file");
EXPECT_EQ(url.to_string(), "file://localhost/my/file");
}
TEST_CASE(file_url_without_hostname)
{
URL url("file:///my/file");
EXPECT_EQ(url.is_valid(), true);
EXPECT_EQ(url.host(), "");
EXPECT_EQ(url.path(), "/my/file");
EXPECT_EQ(url.to_string(), "file:///my/file");
}
TEST_MAIN(URL)

View file

@ -112,8 +112,14 @@ bool URL::parse(const StringView& string)
buffer.append(consume());
continue;
}
if (buffer.is_empty())
if (buffer.is_empty()) {
if (m_protocol == "file") {
m_host = "";
state = State::InPath;
continue;
}
return false;
}
m_host = String::copy(buffer);
buffer.clear();
if (peek() == ':') {