diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp index 940beba7b6..527b735c22 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include namespace Web::Fetch::Infrastructure { @@ -113,7 +113,7 @@ ErrorOr> Response::location_url(Optional const& reques return Optional {}; // 3. If location is a header value, then set location to the result of parsing location with response’s URL. - auto location = AK::URLParser::parse(location_values.first(), url()); + auto location = URL::parse(location_values.first(), url()); if (!location.is_valid()) return Error::from_string_view("Invalid 'Location' header URL"sv); diff --git a/Userland/Libraries/LibWeb/Fetch/Request.cpp b/Userland/Libraries/LibWeb/Fetch/Request.cpp index 7a53304df3..6119156c9f 100644 --- a/Userland/Libraries/LibWeb/Fetch/Request.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Request.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include @@ -18,6 +17,7 @@ #include #include #include +#include namespace Web::Fetch { @@ -121,7 +121,7 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm // 5. If input is a string, then: if (input.has()) { // 1. Let parsedURL be the result of parsing input with baseURL. - auto parsed_url = URLParser::parse(input.get(), base_url); + auto parsed_url = URL::parse(input.get(), base_url); // 2. If parsedURL is failure, then throw a TypeError. if (!parsed_url.is_valid()) @@ -299,7 +299,7 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm // 3. Otherwise: else { // 1. Let parsedReferrer be the result of parsing referrer with baseURL. - auto parsed_referrer = URLParser::parse(referrer, base_url); + auto parsed_referrer = URL::parse(referrer, base_url); // 2. If parsedReferrer is failure, then throw a TypeError. if (!parsed_referrer.is_valid()) diff --git a/Userland/Libraries/LibWeb/Fetch/Response.cpp b/Userland/Libraries/LibWeb/Fetch/Response.cpp index 41b21289af..e60c70541b 100644 --- a/Userland/Libraries/LibWeb/Fetch/Response.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Response.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include namespace Web::Fetch { @@ -174,7 +174,7 @@ WebIDL::ExceptionOr> Response::redirect(JS::VM& vm, S // 1. Let parsedURL be the result of parsing url with current settings object’s API base URL. auto api_base_url = HTML::current_settings_object().api_base_url(); - auto parsed_url = URLParser::parse(url, api_base_url); + auto parsed_url = URL::parse(url, api_base_url); // 2. If parsedURL is failure, then throw a TypeError. if (!parsed_url.is_valid()) diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp index 4740160fdd..57e4c2471d 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include @@ -25,6 +24,7 @@ #include #include #include +#include namespace Web::HTML { @@ -170,7 +170,7 @@ WebIDL::ExceptionOr> resolve_imports_match(DeprecatedString co VERIFY(resolution_result->serialize().ends_with("/"sv)); // 5. Let url be the result of URL parsing afterPrefix with resolutionResult. - auto url = URLParser::parse(after_prefix, *resolution_result); + auto url = URL::parse(after_prefix, *resolution_result); // 6. If url is failure, then throw a TypeError indicating that resolution of normalizedSpecifier was blocked since the afterPrefix portion // could not be URL-parsed relative to the resolutionResult mapped to by the specifierKey prefix. @@ -200,7 +200,7 @@ Optional resolve_url_like_module_specifier(DeprecatedString const& spec // 1. If specifier starts with "/", "./", or "../", then: if (specifier.starts_with("/"sv) || specifier.starts_with("./"sv) || specifier.starts_with("../"sv)) { // 1. Let url be the result of URL parsing specifier with baseURL. - auto url = URLParser::parse(specifier, base_url); + auto url = URL::parse(specifier, base_url); // 2. If url is failure, then return null. if (!url.is_valid()) @@ -211,7 +211,7 @@ Optional resolve_url_like_module_specifier(DeprecatedString const& spec } // 2. Let url be the result of URL parsing specifier (with no base URL). - auto url = URLParser::parse(specifier); + auto url = URL::parse(specifier); // 3. If url is failure, then return null. if (!url.is_valid()) diff --git a/Userland/Libraries/LibWeb/URL/URL.cpp b/Userland/Libraries/LibWeb/URL/URL.cpp index b0b2eab236..f31341c564 100644 --- a/Userland/Libraries/LibWeb/URL/URL.cpp +++ b/Userland/Libraries/LibWeb/URL/URL.cpp @@ -490,4 +490,27 @@ bool host_is_domain(StringView host) && !IPv6Address::from_string(host).has_value(); } +// https://url.spec.whatwg.org/#concept-url-parser +AK::URL parse(StringView input, Optional const& base_url) +{ + // FIXME: We should probably have an extended version of AK::URL for LibWeb instead of standalone functions like this. + + // 1. Let url be the result of running the basic URL parser on input with base and encoding. + auto url = URLParser::basic_parse(input, base_url); + + // 2. If url is failure, return failure. + if (url.is_valid()) + return {}; + + // 3. If url’s scheme is not "blob", + if (url.scheme() != "blob") + return url; + + // FIXME: 4. Set url’s blob URL entry to the result of resolving the blob URL url, + // FIXME: 5. if that did not return failure, and null otherwise. + + // 6. Return url + return url; +} + } diff --git a/Userland/Libraries/LibWeb/URL/URL.h b/Userland/Libraries/LibWeb/URL/URL.h index 3043c9d7ad..8b4c7c79a0 100644 --- a/Userland/Libraries/LibWeb/URL/URL.h +++ b/Userland/Libraries/LibWeb/URL/URL.h @@ -77,4 +77,7 @@ private: HTML::Origin url_origin(AK::URL const&); bool host_is_domain(StringView host); +// https://url.spec.whatwg.org/#concept-url-parser +AK::URL parse(StringView input, Optional const& base_url = {}); + }