From a661daea71be0151e4a155db817ff13be9926582 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 4 Aug 2024 13:33:09 +1200 Subject: [PATCH] LibURL: Don't consider file:// URL hosts as always opaque Which was resulting in file URL hosts not being correctly percent decoded. --- Tests/LibWeb/Text/expected/URL/url.txt | 20 ++++++++++++++++++++ Tests/LibWeb/Text/input/URL/url.html | 1 + Userland/Libraries/LibURL/Parser.cpp | 3 +-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Tests/LibWeb/Text/expected/URL/url.txt b/Tests/LibWeb/Text/expected/URL/url.txt index ecb93109d14..f5744299e8c 100644 --- a/Tests/LibWeb/Text/expected/URL/url.txt +++ b/Tests/LibWeb/Text/expected/URL/url.txt @@ -78,6 +78,16 @@ port => '' pathname => '/d:/' search => '' hash => '' +new URL('file://a%C2%ADb/p', undefined) +protocol => 'file:' +username => '' +password => '' +host => 'ab' +hostname => 'ab' +port => '' +pathname => '/p' +search => '' +hash => '' ========================================= URL.parse('ftp://serenityos.org:21', undefined) protocol => 'ftp:' @@ -159,3 +169,13 @@ port => '' pathname => '/d:/' search => '' hash => '' +URL.parse('file://a%C2%ADb/p', undefined) +protocol => 'file:' +username => '' +password => '' +host => 'ab' +hostname => 'ab' +port => '' +pathname => '/p' +search => '' +hash => '' diff --git a/Tests/LibWeb/Text/input/URL/url.html b/Tests/LibWeb/Text/input/URL/url.html index e6099a7274f..1ec4e8970e1 100644 --- a/Tests/LibWeb/Text/input/URL/url.html +++ b/Tests/LibWeb/Text/input/URL/url.html @@ -22,6 +22,7 @@ { input: 'http://serenityos.org/cat?dog#meow"woof' }, { input: '/hello', base: 'file://friends/' }, { input: '//d:/..', base: 'file:///C:/a/b' }, + { input: 'file://a%C2%ADb/p' }, ]; for (url of urls) { diff --git a/Userland/Libraries/LibURL/Parser.cpp b/Userland/Libraries/LibURL/Parser.cpp index 7663c9fee81..8772b64f7bd 100644 --- a/Userland/Libraries/LibURL/Parser.cpp +++ b/Userland/Libraries/LibURL/Parser.cpp @@ -1485,8 +1485,7 @@ URL Parser::basic_parse(StringView raw_input, Optional const& base_url, Opt // 3. Otherwise, run these steps: else { // 1. Let host be the result of host parsing buffer with url is not special. - // FIXME: It seems we are not passing through url is not special through here - auto host = parse_host(buffer.string_view(), true); + auto host = parse_host(buffer.string_view(), !url->is_special()); // 2. If host is failure, then return failure. if (!host.has_value())