From bfdf7779ce403704f2c924e290464da6503cbdb2 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 17 Sep 2023 13:47:29 +1200 Subject: [PATCH] AK: Correctly set host when parsing URL with a base file:// host We were completely missing this spec step here. Also leave a FIXME for the pre-existing implementation of this step, as this doesn't match the spec. --- AK/URLParser.cpp | 3 +++ Tests/LibWeb/Text/expected/URL/url.txt | 10 ++++++++++ Tests/LibWeb/Text/input/URL/url.html | 1 + 3 files changed, 14 insertions(+) diff --git a/AK/URLParser.cpp b/AK/URLParser.cpp index 9c8de863a7..9e3849739b 100644 --- a/AK/URLParser.cpp +++ b/AK/URLParser.cpp @@ -1377,6 +1377,9 @@ URL URLParser::basic_parse(StringView raw_input, Optional const& base_url, // 1. If base is non-null and base’s scheme is "file", then: if (base_url.has_value() && base_url->m_scheme == "file") { // 1. Set url’s host to base’s host. + url->m_host = base_url->m_host; + + // FIXME: The spec does not seem to mention these steps. url->m_paths = base_url->m_paths; url->m_paths.remove(url->m_paths.size() - 1); diff --git a/Tests/LibWeb/Text/expected/URL/url.txt b/Tests/LibWeb/Text/expected/URL/url.txt index 9ab7cc586d..e2a1dd214d 100644 --- a/Tests/LibWeb/Text/expected/URL/url.txt +++ b/Tests/LibWeb/Text/expected/URL/url.txt @@ -58,3 +58,13 @@ port => '' pathname => '/cat' search => '?dog' hash => '#meow%22woof' +new URL('/hello', 'file://friends/') +protocol => 'file:' +username => '' +password => '' +host => 'friends' +hostname => 'friends' +port => '' +pathname => '/hello' +search => '' +hash => '' diff --git a/Tests/LibWeb/Text/input/URL/url.html b/Tests/LibWeb/Text/input/URL/url.html index 51031e92e5..17fc181aeb 100644 --- a/Tests/LibWeb/Text/input/URL/url.html +++ b/Tests/LibWeb/Text/input/URL/url.html @@ -26,6 +26,7 @@ { input: 'http://[1:1:0:0:1:0:0:0]/' }, { input: 'unknown://serenityos.org:0' }, { input: 'http://serenityos.org/cat?dog#meow"woof' }, + { input: '/hello', base: 'file://friends/' }, ]) { printURL(url.input, url.base); }