1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:47:34 +00:00

AK+Everywhere: Use Optional for URLParser::parse's base_url parameter

This commit is contained in:
networkException 2023-04-11 14:53:40 +02:00 committed by Linus Groh
parent 38bdf4d159
commit 9915fa72fb
12 changed files with 31 additions and 32 deletions

View file

@ -113,8 +113,7 @@ ErrorOr<Optional<AK::URL>> Response::location_url(Optional<String> const& reques
return Optional<AK::URL> {};
// 3. If location is a header value, then set location to the result of parsing location with responses URL.
auto base_url = *url();
auto location = AK::URLParser::parse(location_values.first(), &base_url);
auto location = AK::URLParser::parse(location_values.first(), url());
if (!location.is_valid())
return Error::from_string_view("Invalid 'Location' header URL"sv);

View file

@ -121,7 +121,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
// 5. If input is a string, then:
if (input.has<String>()) {
// 1. Let parsedURL be the result of parsing input with baseURL.
auto parsed_url = URLParser::parse(input.get<String>(), &base_url);
auto parsed_url = URLParser::parse(input.get<String>(), base_url);
// 2. If parsedURL is failure, then throw a TypeError.
if (!parsed_url.is_valid())
@ -299,7 +299,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> 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 = URLParser::parse(referrer, base_url);
// 2. If parsedReferrer is failure, then throw a TypeError.
if (!parsed_referrer.is_valid())

View file

@ -174,7 +174,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::redirect(JS::VM& vm, S
// 1. Let parsedURL be the result of parsing url with current settings objects 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 = URLParser::parse(url, api_base_url);
// 2. If parsedURL is failure, then throw a TypeError.
if (!parsed_url.is_valid())

View file

@ -80,7 +80,7 @@ void HTMLHyperlinkElementUtils::set_protocol(DeprecatedString protocol)
return;
// 3. Basic URL parse the given value, followed by ":", with this element's url as url and scheme start state as state override.
auto result_url = URLParser::parse(DeprecatedString::formatted("{}:", protocol), nullptr, m_url, URLParser::State::SchemeStart);
auto result_url = URLParser::parse(DeprecatedString::formatted("{}:", protocol), {}, m_url, URLParser::State::SchemeStart);
if (result_url.is_valid())
m_url = move(result_url);
@ -194,7 +194,7 @@ void HTMLHyperlinkElementUtils::set_host(DeprecatedString host)
return;
// 4. Basic URL parse the given value, with url as url and host state as state override.
auto result_url = URLParser::parse(host, nullptr, url, URLParser::State::Host);
auto result_url = URLParser::parse(host, {}, url, URLParser::State::Host);
if (result_url.is_valid())
m_url = move(result_url);
@ -227,7 +227,7 @@ void HTMLHyperlinkElementUtils::set_hostname(DeprecatedString hostname)
return;
// 4. Basic URL parse the given value, with url as url and hostname state as state override.
auto result_url = URLParser::parse(hostname, nullptr, m_url, URLParser::State::Hostname);
auto result_url = URLParser::parse(hostname, {}, m_url, URLParser::State::Hostname);
if (result_url.is_valid())
m_url = move(result_url);
@ -269,7 +269,7 @@ void HTMLHyperlinkElementUtils::set_port(DeprecatedString port)
m_url->set_port({});
} else {
// 5. Otherwise, basic URL parse the given value, with url as url and port state as state override.
auto result_url = URLParser::parse(port, nullptr, m_url, URLParser::State::Port);
auto result_url = URLParser::parse(port, {}, m_url, URLParser::State::Port);
if (result_url.is_valid())
m_url = move(result_url);
}
@ -313,7 +313,7 @@ void HTMLHyperlinkElementUtils::set_pathname(DeprecatedString pathname)
url->set_paths({});
// 5. Basic URL parse the given value, with url as url and path start state as state override.
auto result_url = URLParser::parse(pathname, nullptr, move(url), URLParser::State::PathStart);
auto result_url = URLParser::parse(pathname, {}, move(url), URLParser::State::PathStart);
if (result_url.is_valid())
m_url = move(result_url);
@ -360,7 +360,7 @@ void HTMLHyperlinkElementUtils::set_search(DeprecatedString search)
url_copy->set_query(DeprecatedString::empty());
// 3. Basic URL parse input, with null, this element's node document's document's character encoding, url as url, and query state as state override.
auto result_url = URLParser::parse(input, nullptr, move(url_copy), URLParser::State::Query);
auto result_url = URLParser::parse(input, {}, move(url_copy), URLParser::State::Query);
if (result_url.is_valid())
m_url = move(result_url);
}
@ -408,7 +408,7 @@ void HTMLHyperlinkElementUtils::set_hash(DeprecatedString hash)
url_copy->set_fragment(DeprecatedString::empty());
// 3. Basic URL parse input, with url as url and fragment state as state override.
auto result_url = URLParser::parse(input, nullptr, move(url_copy), URLParser::State::Fragment);
auto result_url = URLParser::parse(input, {}, move(url_copy), URLParser::State::Fragment);
if (result_url.is_valid())
m_url = move(result_url);
}

View file

@ -312,7 +312,7 @@ WebIDL::ExceptionOr<void> Location::set_hash(String const& value)
copy_url.set_fragment("");
// 6. Basic URL parse input, with copyURL as url and fragment state as state override.
auto result_url = URLParser::parse(input, nullptr, copy_url, URLParser::State::Fragment);
auto result_url = URLParser::parse(input, {}, copy_url, URLParser::State::Fragment);
// 7. If copyURL's fragment is this's url's fragment, then return.
if (copy_url.fragment() == this->url().fragment())

View file

@ -159,7 +159,7 @@ WebIDL::ExceptionOr<Optional<AK::URL>> 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 = URLParser::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.
@ -189,7 +189,7 @@ Optional<AK::URL> 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 = URLParser::parse(specifier, base_url);
// 2. If url is failure, then return null.
if (!url.is_valid())

View file

@ -135,7 +135,7 @@ WebIDL::ExceptionOr<void> URL::set_protocol(String const& protocol)
auto& vm = realm().vm();
// basic URL parse the given value, followed by U+003A (:), with thiss URL as url and scheme start state as state override.
auto result_url = URLParser::parse(TRY_OR_THROW_OOM(vm, String::formatted("{}:", protocol)), nullptr, m_url, URLParser::State::SchemeStart);
auto result_url = URLParser::parse(TRY_OR_THROW_OOM(vm, String::formatted("{}:", protocol)), {}, m_url, URLParser::State::SchemeStart);
if (result_url.is_valid())
m_url = move(result_url);
return {};
@ -197,7 +197,7 @@ void URL::set_host(String const& host)
if (m_url.cannot_be_a_base_url())
return;
// 2. Basic URL parse the given value with thiss URL as url and host state as state override.
auto result_url = URLParser::parse(host, nullptr, m_url, URLParser::State::Host);
auto result_url = URLParser::parse(host, {}, m_url, URLParser::State::Host);
if (result_url.is_valid())
m_url = move(result_url);
}
@ -219,7 +219,7 @@ void URL::set_hostname(String const& hostname)
if (m_url.cannot_be_a_base_url())
return;
// 2. Basic URL parse the given value with thiss URL as url and hostname state as state override.
auto result_url = URLParser::parse(hostname, nullptr, m_url, URLParser::State::Hostname);
auto result_url = URLParser::parse(hostname, {}, m_url, URLParser::State::Hostname);
if (result_url.is_valid())
m_url = move(result_url);
}
@ -249,7 +249,7 @@ void URL::set_port(String const& port)
}
// 3. Otherwise, basic URL parse the given value with thiss URL as url and port state as state override.
auto result_url = URLParser::parse(port, nullptr, m_url, URLParser::State::Port);
auto result_url = URLParser::parse(port, {}, m_url, URLParser::State::Port);
if (result_url.is_valid())
m_url = move(result_url);
}
@ -273,7 +273,7 @@ void URL::set_pathname(String const& pathname)
auto url = m_url; // We copy the URL here to follow other browser's behaviour of reverting the path change if the parse failed.
url.set_paths({});
// 3. Basic URL parse the given value with thiss URL as url and path start state as state override.
auto result_url = URLParser::parse(pathname, nullptr, move(url), URLParser::State::PathStart);
auto result_url = URLParser::parse(pathname, {}, move(url), URLParser::State::PathStart);
if (result_url.is_valid())
m_url = move(result_url);
}
@ -308,7 +308,7 @@ WebIDL::ExceptionOr<void> URL::set_search(String const& search)
auto url_copy = url; // We copy the URL here to follow other browser's behaviour of reverting the search change if the parse failed.
url_copy.set_query(DeprecatedString::empty());
// 4. Basic URL parse input with url as url and query state as state override.
auto result_url = URLParser::parse(input, nullptr, move(url_copy), URLParser::State::Query);
auto result_url = URLParser::parse(input, {}, move(url_copy), URLParser::State::Query);
if (result_url.is_valid()) {
m_url = move(result_url);
// 5. Set thiss query objects list to the result of parsing input.
@ -348,7 +348,7 @@ void URL::set_hash(String const& hash)
auto url = m_url; // We copy the URL here to follow other browser's behaviour of reverting the hash change if the parse failed.
url.set_fragment(DeprecatedString::empty());
// 4. Basic URL parse input with thiss URL as url and fragment state as state override.
auto result_url = URLParser::parse(input, nullptr, move(url), URLParser::State::Fragment);
auto result_url = URLParser::parse(input, {}, move(url), URLParser::State::Fragment);
if (result_url.is_valid())
m_url = move(result_url);
}