diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 2d0dd59384b..4dd82316abc 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -1128,7 +1128,7 @@ URL::URL Document::parse_url(StringView url) const auto base_url = this->base_url(); // 2. Return the result of applying the URL parser to url, with baseURL. - return DOMURL::parse(url, base_url); + return DOMURL::parse(url, base_url).value_or(URL::URL {}); } // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#encoding-parsing-a-url @@ -1145,7 +1145,7 @@ URL::URL Document::encoding_parse_url(StringView url) const auto base_url = this->base_url(); // 5. Return the result of applying the URL parser to url, with baseURL and encoding. - return DOMURL::parse(url, base_url, encoding); + return DOMURL::parse(url, base_url, encoding).value_or(URL::URL {}); } // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#encoding-parsing-and-serializing-a-url diff --git a/Libraries/LibWeb/DOMURL/DOMURL.cpp b/Libraries/LibWeb/DOMURL/DOMURL.cpp index 9b79f371b92..7945a799abb 100644 --- a/Libraries/LibWeb/DOMURL/DOMURL.cpp +++ b/Libraries/LibWeb/DOMURL/DOMURL.cpp @@ -133,15 +133,15 @@ void DOMURL::revoke_object_url(JS::VM&, StringView url) auto url_record = parse(url); // Spec Bug: https://github.com/w3c/FileAPI/issues/207, missing check for URL failure parsing. - if (!url_record.is_valid()) + if (!url_record.has_value()) return; // 2. If url record’s scheme is not "blob", return. - if (url_record.scheme() != "blob"sv) + if (url_record->scheme() != "blob"sv) return; // 3. Let entry be urlRecord’s blob URL entry. - auto& entry = url_record.blob_url_entry(); + auto const& entry = url_record->blob_url_entry(); // 4. If entry is null, return. if (!entry.has_value()) @@ -156,7 +156,7 @@ void DOMURL::revoke_object_url(JS::VM&, StringView url) // 7. Remove an entry from the Blob URL Store for url. // FIXME: Spec bug: https://github.com/w3c/FileAPI/issues/207, urlRecord should instead be passed through. - FileAPI::remove_entry_from_blob_url_store(url_record); + FileAPI::remove_entry_from_blob_url_store(*url_record); } // https://url.spec.whatwg.org/#dom-url-canparse @@ -485,7 +485,7 @@ void strip_trailing_spaces_from_an_opaque_path(DOMURL& url) } // https://url.spec.whatwg.org/#concept-url-parser -URL::URL parse(StringView input, Optional base_url, Optional encoding) +Optional parse(StringView input, Optional base_url, Optional encoding) { // FIXME: We should probably have an extended version of URL::URL for LibWeb instead of standalone functions like this. @@ -494,7 +494,7 @@ URL::URL parse(StringView input, Optional base_url, Optionalscheme() != "blob") diff --git a/Libraries/LibWeb/DOMURL/DOMURL.h b/Libraries/LibWeb/DOMURL/DOMURL.h index 9d150eef12f..3dd016dc74a 100644 --- a/Libraries/LibWeb/DOMURL/DOMURL.h +++ b/Libraries/LibWeb/DOMURL/DOMURL.h @@ -96,6 +96,6 @@ private: void strip_trailing_spaces_from_an_opaque_path(DOMURL& url); // https://url.spec.whatwg.org/#concept-url-parser -URL::URL parse(StringView input, Optional base_url = {}, Optional encoding = {}); +Optional parse(StringView input, Optional base_url = {}, Optional encoding = {}); } diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp index 5a890b0aadf..bb26e3c8f04 100644 --- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp +++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp @@ -135,12 +135,12 @@ ErrorOr> Response::location_url(Optional const& reque // 3. If location is a header value, then set location to the result of parsing location with response’s URL. auto location = DOMURL::parse(location_values.first(), url()); - if (!location.is_valid()) + if (!location.has_value()) return Error::from_string_literal("Invalid 'Location' header URL"); // 4. If location is a URL whose fragment is null, then set location’s fragment to requestFragment. - if (!location.fragment().has_value()) - location.set_fragment(request_fragment); + if (!location->fragment().has_value()) + location->set_fragment(request_fragment); // 5. Return location. return location; diff --git a/Libraries/LibWeb/Fetch/Request.cpp b/Libraries/LibWeb/Fetch/Request.cpp index 86fb49f34d5..ca1a1b415de 100644 --- a/Libraries/LibWeb/Fetch/Request.cpp +++ b/Libraries/LibWeb/Fetch/Request.cpp @@ -124,16 +124,16 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm& realm, auto parsed_url = DOMURL::parse(input.get(), base_url); // 2. If parsedURL is failure, then throw a TypeError. - if (!parsed_url.is_valid()) + if (!parsed_url.has_value()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Input URL is not valid"sv }; // 3. If parsedURL includes credentials, then throw a TypeError. - if (parsed_url.includes_credentials()) + if (parsed_url->includes_credentials()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Input URL must not include credentials"sv }; // 4. Set request to a new request whose URL is parsedURL. input_request = Infrastructure::Request::create(vm); - input_request->set_url(move(parsed_url)); + input_request->set_url(parsed_url.release_value()); // 5. Set fallbackMode to "cors". fallback_mode = Infrastructure::Request::Mode::CORS; @@ -302,21 +302,21 @@ WebIDL::ExceptionOr> Request::construct_impl(JS::Realm& realm, auto parsed_referrer = DOMURL::parse(referrer, base_url); // 2. If parsedReferrer is failure, then throw a TypeError. - if (!parsed_referrer.is_valid()) + if (!parsed_referrer.has_value()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Referrer must be a valid URL"sv }; // 3. If one of the following is true // - parsedReferrer’s scheme is "about" and path is the string "client" // - parsedReferrer’s origin is not same origin with origin // then set request’s referrer to "client". - auto parsed_referrer_origin = parsed_referrer.origin(); - if ((parsed_referrer.scheme() == "about"sv && parsed_referrer.paths().size() == 1 && parsed_referrer.paths()[0] == "client"sv) + auto parsed_referrer_origin = parsed_referrer->origin(); + if ((parsed_referrer->scheme() == "about"sv && parsed_referrer->paths().size() == 1 && parsed_referrer->paths()[0] == "client"sv) || !parsed_referrer_origin.is_same_origin(origin)) { request->set_referrer(Infrastructure::Request::Referrer::Client); } // 4. Otherwise, set request’s referrer to parsedReferrer. else { - request->set_referrer(move(parsed_referrer)); + request->set_referrer(parsed_referrer.release_value()); } } } diff --git a/Libraries/LibWeb/Fetch/Response.cpp b/Libraries/LibWeb/Fetch/Response.cpp index 51cb9347085..731d388f5fc 100644 --- a/Libraries/LibWeb/Fetch/Response.cpp +++ b/Libraries/LibWeb/Fetch/Response.cpp @@ -186,7 +186,7 @@ WebIDL::ExceptionOr> Response::redirect(JS::VM& vm, String con auto parsed_url = DOMURL::parse(url, api_base_url); // 2. If parsedURL is failure, then throw a TypeError. - if (!parsed_url.is_valid()) + if (!parsed_url.has_value()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Redirect URL is not valid"sv }; // 3. If status is not a redirect status, then throw a RangeError. @@ -201,7 +201,7 @@ WebIDL::ExceptionOr> Response::redirect(JS::VM& vm, String con response_object->response()->set_status(status); // 6. Let value be parsedURL, serialized and isomorphic encoded. - auto value = parsed_url.serialize(); + auto value = parsed_url->serialize(); // 7. Append (`Location`, value) to responseObject’s response’s header list. auto header = Infrastructure::Header::from_string_pair("Location"sv, value); diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 5fc3552cff6..7a6c6566c86 100644 --- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -268,11 +268,11 @@ GC::Ptr HTMLLinkElement::create_link_request(HTM auto url = DOMURL::parse(options.href, options.base_url); // 4. If url is failure, then return null. - if (!url.is_valid()) + if (!url.has_value()) return nullptr; // 5. Let request be the result of creating a potential-CORS request given url, options's destination, and options's crossorigin. - auto request = create_potential_CORS_request(vm(), url, options.destination, options.crossorigin); + auto request = create_potential_CORS_request(vm(), *url, options.destination, options.crossorigin); // 6. Set request's policy container to options's policy container. request->set_policy_container(options.policy_container); diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Libraries/LibWeb/HTML/Scripting/Environments.cpp index 6f7a0c8784a..55e154688cc 100644 --- a/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -205,7 +205,7 @@ URL::URL EnvironmentSettingsObject::parse_url(StringView url) auto base_url = api_base_url(); // 2. Return the result of applying the URL parser to url, with baseURL. - return DOMURL::parse(url, base_url); + return DOMURL::parse(url, base_url).value_or(URL::URL {}); } // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#encoding-parsing-a-url @@ -225,7 +225,7 @@ URL::URL EnvironmentSettingsObject::encoding_parse_url(StringView url) auto base_url = api_base_url(); // 5. Return the result of applying the URL parser to url, with baseURL and encoding. - return DOMURL::parse(url, base_url, encoding); + return DOMURL::parse(url, base_url, encoding).value_or(URL::URL {}); } // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#encoding-parsing-and-serializing-a-url diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp index a9456a57836..159f30fae3c 100644 --- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp +++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp @@ -221,15 +221,15 @@ WebIDL::ExceptionOr> resolve_imports_match(ByteString const& // 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. - if (!url.is_valid()) + if (!url.has_value()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Could not resolve '{}' as the after prefix portion could not be URL-parsed.", normalized_specifier).release_value_but_fixme_should_propagate_errors() }; // 7. Assert: url is a URL. - VERIFY(url.is_valid()); + VERIFY(url.has_value()); // 8. If the serialization of resolutionResult is not a code unit prefix of the serialization of url, then throw a TypeError indicating // that the resolution of normalizedSpecifier was blocked due to it backtracking above its prefix specifierKey. - if (!Infra::is_code_unit_prefix(resolution_result->serialize(), url.serialize())) + if (!Infra::is_code_unit_prefix(resolution_result->serialize(), url->serialize())) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Could not resolve '{}' as it backtracks above its prefix specifierKey.", normalized_specifier).release_value_but_fixme_should_propagate_errors() }; // 9. Return url. @@ -250,7 +250,7 @@ Optional resolve_url_like_module_specifier(ByteString const& specifier auto url = DOMURL::parse(specifier, base_url); // 2. If url is failure, then return null. - if (!url.is_valid()) + if (!url.has_value()) return {}; // 3. Return url. @@ -261,7 +261,7 @@ Optional resolve_url_like_module_specifier(ByteString const& specifier auto url = DOMURL::parse(specifier); // 3. If url is failure, then return null. - if (!url.is_valid()) + if (!url.has_value()) return {}; // 4. Return url. diff --git a/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp b/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp index cc609e3e12f..6347af808df 100644 --- a/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp +++ b/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp @@ -202,7 +202,7 @@ WebIDL::ExceptionOr> sort_and_normalise_sc auto scope_prefix_url = DOMURL::parse(scope_prefix.as_string(), base_url); // 3. If scopePrefixURL is failure, then: - if (!scope_prefix_url.is_valid()) { + if (!scope_prefix_url.has_value()) { // 1. The user agent may report a warning to the console that the scope prefix URL was not parseable. auto& console = realm.intrinsics().console_object()->console(); console.output_debug_message(JS::Console::LogLevel::Warn, @@ -213,7 +213,7 @@ WebIDL::ExceptionOr> sort_and_normalise_sc } // 4. Let normalizedScopePrefix be the serialization of scopePrefixURL. - auto normalised_scope_prefix = scope_prefix_url.serialize(); + auto normalised_scope_prefix = scope_prefix_url->serialize(); // 5. Set normalized[normalizedScopePrefix] to the result of sorting and normalizing a module specifier map given potentialSpecifierMap and baseURL. normalised.set(normalised_scope_prefix, TRY(sort_and_normalise_module_specifier_map(realm, potential_specifier_map.as_object(), base_url))); diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cpp index d925a2a153f..06b718e2bf9 100644 --- a/Libraries/LibWeb/HTML/Window.cpp +++ b/Libraries/LibWeb/HTML/Window.cpp @@ -1105,11 +1105,11 @@ WebIDL::ExceptionOr Window::window_post_message_steps(JS::Value message, W auto parsed_url = DOMURL::parse(options.target_origin); // 2. If parsedURL is failure, then throw a "SyntaxError" DOMException. - if (!parsed_url.is_valid()) + if (!parsed_url.has_value()) return WebIDL::SyntaxError::create(target_realm, MUST(String::formatted("Invalid URL for targetOrigin: '{}'", options.target_origin))); // 3. Set targetOrigin to parsedURL's origin. - target_origin = parsed_url.origin(); + target_origin = parsed_url->origin(); } // 6. Let transfer be options["transfer"]. diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp index bf9ccc83193..0e205a7a8cd 100644 --- a/Libraries/LibWeb/Internals/Internals.cpp +++ b/Libraries/LibWeb/Internals/Internals.cpp @@ -167,14 +167,14 @@ void Internals::spoof_current_url(String const& url_string) { auto url = DOMURL::parse(url_string); - VERIFY(url.is_valid()); + VERIFY(url.has_value()); - auto origin = url.origin(); + auto origin = url->origin(); auto& window = internals_window(); - window.associated_document().set_url(url); + window.associated_document().set_url(url.value()); window.associated_document().set_origin(origin); - HTML::relevant_settings_object(window.associated_document()).creation_url = url; + HTML::relevant_settings_object(window.associated_document()).creation_url = url.release_value(); } GC::Ref Internals::create_internal_animation_timeline() diff --git a/Libraries/LibWeb/ServiceWorker/Job.cpp b/Libraries/LibWeb/ServiceWorker/Job.cpp index 329b5ffcb9a..68c9399e178 100644 --- a/Libraries/LibWeb/ServiceWorker/Job.cpp +++ b/Libraries/LibWeb/ServiceWorker/Job.cpp @@ -302,7 +302,7 @@ static void update(JS::VM& vm, GC::Ref job) auto resolved_scope = DOMURL::parse("./"sv, job->script_url); // 2. Set maxScopeString to "/", followed by the strings in resolvedScope’s path (including empty strings), separated from each other by "/". - max_scope_string = join_paths_with_slash(resolved_scope); + max_scope_string = join_paths_with_slash(*resolved_scope); } // 14. Else: else { @@ -310,9 +310,9 @@ static void update(JS::VM& vm, GC::Ref job) auto max_scope = DOMURL::parse(service_worker_allowed.get>()[0], job->script_url); // 2. If maxScope’s origin is job’s script url's origin, then: - if (max_scope.origin().is_same_origin(job->script_url.origin())) { + if (max_scope->origin().is_same_origin(job->script_url.origin())) { // 1. Set maxScopeString to "/", followed by the strings in maxScope’s path (including empty strings), separated from each other by "/". - max_scope_string = join_paths_with_slash(max_scope); + max_scope_string = join_paths_with_slash(*max_scope); } } diff --git a/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.cpp b/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.cpp index a31e75cf36d..fa087bb1287 100644 --- a/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.cpp +++ b/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.cpp @@ -81,13 +81,13 @@ GC::Ref ServiceWorkerContainer::register_(String script_url, Re } // https://w3c.github.io/ServiceWorker/#start-register-algorithm -void ServiceWorkerContainer::start_register(Optional scope_url, URL::URL script_url, GC::Ref promise, HTML::EnvironmentSettingsObject& client, URL::URL referrer, Bindings::WorkerType worker_type, Bindings::ServiceWorkerUpdateViaCache update_via_cache) +void ServiceWorkerContainer::start_register(Optional scope_url, Optional script_url, GC::Ref promise, HTML::EnvironmentSettingsObject& client, URL::URL referrer, Bindings::WorkerType worker_type, Bindings::ServiceWorkerUpdateViaCache update_via_cache) { auto& realm = this->realm(); auto& vm = realm.vm(); // 1. If scriptURL is failure, reject promise with a TypeError and abort these steps. - if (!script_url.is_valid()) { + if (!script_url.has_value()) { WebIDL::reject_promise(realm, promise, JS::TypeError::create(realm, "scriptURL is not a valid URL"sv)); return; } @@ -95,17 +95,17 @@ void ServiceWorkerContainer::start_register(Optional scope_url, URL::U // 2. Set scriptURL’s fragment to null. // Note: The user agent does not store the fragment of the script’s url. // This means that the fragment does not have an effect on identifying service workers. - script_url.set_fragment({}); + script_url->set_fragment({}); // 3. If scriptURL’s scheme is not one of "http" and "https", reject promise with a TypeError and abort these steps. - if (!script_url.scheme().is_one_of("http"sv, "https"sv)) { + if (!script_url->scheme().is_one_of("http"sv, "https"sv)) { WebIDL::reject_promise(realm, promise, JS::TypeError::create(realm, "scriptURL must have a scheme of 'http' or 'https'"sv)); return; } // 4. If any of the strings in scriptURL’s path contains either ASCII case-insensitive "%2f" or ASCII case-insensitive "%5c", // reject promise with a TypeError and abort these steps. - auto invalid_path = script_url.paths().first_matching([&](auto& path) { + auto invalid_path = script_url->paths().first_matching([&](auto& path) { return path.contains("%2f"sv, CaseSensitivity::CaseInsensitive) || path.contains("%5c"sv, CaseSensitivity::CaseInsensitive); }); if (invalid_path.has_value()) { @@ -156,7 +156,7 @@ void ServiceWorkerContainer::start_register(Optional scope_url, URL::U } // 11. Let job be the result of running Create Job with register, storage key, scopeURL, scriptURL, promise, and client. - auto job = Job::create(vm, Job::Type::Register, storage_key.value(), scope_url.value(), script_url, promise, client); + auto job = Job::create(vm, Job::Type::Register, storage_key.value(), scope_url.value(), script_url.release_value(), promise, client); // 12. Set job’s worker type to workerType. job->worker_type = worker_type; diff --git a/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.h b/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.h index 58780889926..39dac835c58 100644 --- a/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.h +++ b/Libraries/LibWeb/ServiceWorker/ServiceWorkerContainer.h @@ -49,7 +49,7 @@ private: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; - void start_register(Optional scope_url, URL::URL script_url, GC::Ref, HTML::EnvironmentSettingsObject&, URL::URL referrer, Bindings::WorkerType, Bindings::ServiceWorkerUpdateViaCache); + void start_register(Optional scope_url, Optional script_url, GC::Ref, HTML::EnvironmentSettingsObject&, URL::URL referrer, Bindings::WorkerType, Bindings::ServiceWorkerUpdateViaCache); GC::Ref m_service_worker_client; }; diff --git a/Libraries/LibWeb/WebSockets/WebSocket.cpp b/Libraries/LibWeb/WebSockets/WebSocket.cpp index f86e48adeb0..b890a4c34a4 100644 --- a/Libraries/LibWeb/WebSockets/WebSocket.cpp +++ b/Libraries/LibWeb/WebSockets/WebSocket.cpp @@ -49,22 +49,22 @@ WebIDL::ExceptionOr> WebSocket::construct_impl(JS::Realm& rea auto url_record = DOMURL::parse(url, base_url); // 3. If urlRecord is failure, then throw a "SyntaxError" DOMException. - if (!url_record.is_valid()) + if (!url_record.has_value()) return WebIDL::SyntaxError::create(realm, "Invalid URL"_string); // 4. If urlRecord’s scheme is "http", then set urlRecord’s scheme to "ws". - if (url_record.scheme() == "http"sv) - url_record.set_scheme("ws"_string); + if (url_record->scheme() == "http"sv) + url_record->set_scheme("ws"_string); // 5. Otherwise, if urlRecord’s scheme is "https", set urlRecord’s scheme to "wss". - else if (url_record.scheme() == "https"sv) - url_record.set_scheme("wss"_string); + else if (url_record->scheme() == "https"sv) + url_record->set_scheme("wss"_string); // 6. If urlRecord’s scheme is not "ws" or "wss", then throw a "SyntaxError" DOMException. - if (!url_record.scheme().is_one_of("ws"sv, "wss"sv)) + if (!url_record->scheme().is_one_of("ws"sv, "wss"sv)) return WebIDL::SyntaxError::create(realm, "Invalid protocol"_string); // 7. If urlRecord’s fragment is non-null, then throw a "SyntaxError" DOMException. - if (url_record.fragment().has_value()) + if (url_record->fragment().has_value()) return WebIDL::SyntaxError::create(realm, "Presence of URL fragment is invalid"_string); Vector protocols_sequence; @@ -94,14 +94,14 @@ WebIDL::ExceptionOr> WebSocket::construct_impl(JS::Realm& rea } // 10. Set this's url to urlRecord. - web_socket->set_url(url_record); + web_socket->set_url(*url_record); // 11. Let client be this’s relevant settings object. auto& client = relevant_settings_object; // FIXME: 12. Run this step in parallel: // 1. Establish a WebSocket connection given urlRecord, protocols, and client. [FETCH] - TRY_OR_THROW_OOM(vm, web_socket->establish_web_socket_connection(url_record, protocols_sequence, client)); + TRY_OR_THROW_OOM(vm, web_socket->establish_web_socket_connection(*url_record, protocols_sequence, client)); return web_socket; } diff --git a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 5d0cd39a858..9219b0cf3e3 100644 --- a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -487,20 +487,20 @@ WebIDL::ExceptionOr XMLHttpRequest::open(String const& method_string, Stri auto parsed_url = DOMURL::parse(url, api_base_url, api_url_character_encoding); // 6. If parsedURL is failure, then throw a "SyntaxError" DOMException. - if (!parsed_url.is_valid()) + if (!parsed_url.has_value()) return WebIDL::SyntaxError::create(realm(), "Invalid URL"_string); // 7. If the async argument is omitted, set async to true, and set username and password to null. // NOTE: This is handled in the overload lacking the async argument. // 8. If parsedURL’s host is non-null, then: - if (parsed_url.host().has_value()) { + if (parsed_url->host().has_value()) { // 1. If the username argument is not null, set the username given parsedURL and username. if (username.has_value()) - parsed_url.set_username(username.value()); + parsed_url->set_username(username.value()); // 2. If the password argument is not null, set the password given parsedURL and password. if (password.has_value()) - parsed_url.set_password(password.value()); + parsed_url->set_password(password.value()); } // 9. If async is false, the current global object is a Window object, and either this’s timeout is @@ -523,7 +523,7 @@ WebIDL::ExceptionOr XMLHttpRequest::open(String const& method_string, Stri // Set this’s request method to method. m_request_method = normalized_method.span(); // Set this’s request URL to parsedURL. - m_request_url = parsed_url; + m_request_url = parsed_url.release_value(); // Set this’s synchronous flag if async is false; otherwise unset this’s synchronous flag. m_synchronous = !async; // Empty this’s author request headers. diff --git a/Libraries/LibWebView/SourceHighlighter.cpp b/Libraries/LibWebView/SourceHighlighter.cpp index f4ab5b5f96f..038d97d6e48 100644 --- a/Libraries/LibWebView/SourceHighlighter.cpp +++ b/Libraries/LibWebView/SourceHighlighter.cpp @@ -286,9 +286,7 @@ String SourceHighlighterClient::to_html_string(URL::URL const& url, URL::URL con auto attribute_url = MUST(String::formatted("{}", attribute_value)); auto attribute_url_without_quotes = attribute_url.bytes_as_string_view().trim("\""sv); - if (auto resolved = Web::DOMURL::parse(attribute_url_without_quotes, base_url); resolved.is_valid()) - return resolved; - return {}; + return Web::DOMURL::parse(attribute_url_without_quotes, base_url); }; size_t span_index = 0;