diff --git a/Libraries/LibURL/URL.cpp b/Libraries/LibURL/URL.cpp index 8a82f790854..8a087cdaaf4 100644 --- a/Libraries/LibURL/URL.cpp +++ b/Libraries/LibURL/URL.cpp @@ -169,15 +169,19 @@ URL create_with_file_scheme(ByteString const& path, ByteString const& fragment, if (!lexical_path.is_absolute()) return {}; - URL url; - url.set_scheme("file"_string); - url.set_host(hostname == "localhost" ? String {} : String::from_byte_string(hostname).release_value_but_fixme_should_propagate_errors()); - url.set_paths(lexical_path.parts()); + StringBuilder url_builder; + url_builder.append("file://"sv); + url_builder.append(hostname); + url_builder.append(lexical_path.string()); if (path.ends_with('/')) - url.append_slash(); - if (!fragment.is_empty()) - url.set_fragment(String::from_byte_string(fragment).release_value_but_fixme_should_propagate_errors()); - return url; + url_builder.append('/'); + if (!fragment.is_empty()) { + url_builder.append('#'); + url_builder.append(fragment); + } + + auto url = Parser::basic_parse(url_builder.string_view()); + return url.has_value() ? url.release_value() : URL {}; } URL create_with_url_or_path(ByteString const& url_or_path) diff --git a/Libraries/LibWebView/URL.cpp b/Libraries/LibWebView/URL.cpp index d78453aadbd..39e314a8f0c 100644 --- a/Libraries/LibWebView/URL.cpp +++ b/Libraries/LibWebView/URL.cpp @@ -45,11 +45,11 @@ Optional sanitize_url(StringView location, Optional cons } static constexpr Array SUPPORTED_SCHEMES { "about"sv, "data"sv, "file"sv, "http"sv, "https"sv, "resource"sv }; - if (!any_of(SUPPORTED_SCHEMES, [&](StringView const& scheme) { return scheme == url.scheme(); })) + if (!any_of(SUPPORTED_SCHEMES, [&](StringView const& scheme) { return scheme == url->scheme(); })) return search_url_or_error(); // FIXME: Add support for other schemes, e.g. "mailto:". Firefox and Chrome open mailto: locations. - auto const& host = url.host(); + auto const& host = url->host(); if (host.has_value() && host->is_domain()) { auto const& domain = host->get(); @@ -64,7 +64,7 @@ Optional sanitize_url(StringView location, Optional cons auto public_suffix = URL::get_public_suffix(domain); if (!public_suffix.has_value() || *public_suffix == domain) { if (append_tld == AppendTLD::Yes) - url.set_host(MUST(String::formatted("{}.com", domain))); + url->set_host(MUST(String::formatted("{}.com", domain))); else if (https_scheme_was_guessed && domain != "localhost"sv) return search_url_or_error(); } diff --git a/UI/Headless/Test.cpp b/UI/Headless/Test.cpp index 446071c4fc1..8f2c5d54dfd 100644 --- a/UI/Headless/Test.cpp +++ b/UI/Headless/Test.cpp @@ -422,7 +422,7 @@ static void run_test(HeadlessWebView& view, Test& test, Application& app) view.on_test_finish = {}; promise->when_resolved([&view, &test, &app](auto) { - auto url = URL::create_with_file_scheme(MUST(FileSystem::real_path(test.input_path))); + auto url = URL::create_with_file_scheme(MUST(FileSystem::real_path(test.input_path))).release_value(); switch (test.mode) { case TestMode::Crash: diff --git a/Utilities/xml.cpp b/Utilities/xml.cpp index 9014b60b1ae..c71bc056a39 100644 --- a/Utilities/xml.cpp +++ b/Utilities/xml.cpp @@ -435,7 +435,7 @@ static void do_run_tests(XML::Document& document) path_builder.append(suite.attributes.find("URI")->value); auto url = URL::create_with_file_scheme(path_builder.string_view()); - auto file_path = URL::percent_decode(url.serialize_path()); + auto file_path = URL::percent_decode(url->serialize_path()); auto file_result = Core::File::open(file_path, Core::File::OpenMode::Read); if (file_result.is_error()) { warnln("Read error for {}: {}", file_path, file_result.error());