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

AK: Port URL::m_query from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-08-12 19:28:19 +12:00 committed by Andrew Kaster
parent 55a01e72ca
commit 21fe86d235
14 changed files with 63 additions and 75 deletions

View file

@ -616,7 +616,7 @@ ErrorOr<void> HTMLFormElement::mutate_action_url(AK::URL parsed_action, Vector<X
auto query = TRY(url_encode(pairs, encoding));
// 3. Set parsed action's query component to query.
parsed_action.set_query(query.to_deprecated_string());
parsed_action.set_query(query);
// 4. Plan to navigate to parsed action.
plan_to_navigate_to(move(parsed_action), target_navigable, history_handling);
@ -715,7 +715,7 @@ ErrorOr<void> HTMLFormElement::mail_with_headers(AK::URL parsed_action, Vector<X
TRY(headers.replace("+"sv, "%20"sv, ReplaceMode::All));
// 4. Set parsed action's query to headers.
parsed_action.set_query(headers.to_deprecated_string());
parsed_action.set_query(headers);
// 5. Plan to navigate to parsed action.
plan_to_navigate_to(move(parsed_action), target_navigable, history_handling);
@ -751,15 +751,15 @@ ErrorOr<void> HTMLFormElement::mail_as_body(AK::URL parsed_action, Vector<XHR::F
}
// 3. If parsed action's query is null, then set it to the empty string.
if (parsed_action.query().is_null())
parsed_action.set_query(DeprecatedString::empty());
if (!parsed_action.query().has_value())
parsed_action.set_query(String {});
StringBuilder query_builder;
TRY(query_builder.try_append(parsed_action.query()));
query_builder.append(*parsed_action.query());
// 4. If parsed action's query is not the empty string, then append a single U+0026 AMPERSAND character (&) to it.
if (!parsed_action.query().is_empty())
if (!parsed_action.query()->is_empty())
TRY(query_builder.try_append('&'));
// 5. Append "body=" to parsed action's query.
@ -768,7 +768,7 @@ ErrorOr<void> HTMLFormElement::mail_as_body(AK::URL parsed_action, Vector<XHR::F
// 6. Append body to parsed action's query.
TRY(query_builder.try_append(body));
parsed_action.set_query(query_builder.to_deprecated_string());
parsed_action.set_query(MUST(query_builder.to_string()));
// 7. Plan to navigate to parsed action.
plan_to_navigate_to(move(parsed_action), target_navigable, history_handling);

View file

@ -330,7 +330,7 @@ DeprecatedString HTMLHyperlinkElementUtils::search() const
// 2. Let url be this element's url.
// 3. If url is null, or url's query is either null or the empty string, return the empty string.
if (!m_url.has_value() || m_url->query().is_null() || m_url->query().is_empty())
if (!m_url.has_value() || m_url->query().has_value() || m_url->query()->is_empty())
return DeprecatedString::empty();
// 4. Return "?", followed by url's query.
@ -358,7 +358,7 @@ void HTMLHyperlinkElementUtils::set_search(DeprecatedString search)
// 2. Set url's query to the empty string.
auto url_copy = m_url; // We copy the URL here to follow other browser's behavior of reverting the search change if the parse failed.
url_copy->set_query(DeprecatedString::empty());
url_copy->set_query(String {});
// 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::basic_parse(input, {}, move(url_copy), URLParser::State::Query);

View file

@ -253,7 +253,7 @@ WebIDL::ExceptionOr<String> Location::search() const
auto url = this->url();
// 2. If this's url's query is either null or the empty string, return the empty string.
if (url.query().is_empty())
if (!url.query().has_value() || url.query()->is_empty())
return String {};
// 3. Return "?", followed by this's url's query.

View file

@ -106,11 +106,11 @@ WebIDL::ExceptionOr<String> WorkerLocation::search() const
auto const& query = m_global_scope->url().query();
// 2. If query is either null or the empty string, return the empty string.
if (query.is_empty())
if (!query.has_value() || query->is_empty())
return String {};
// 3. Return "?", followed by query.
return TRY_OR_THROW_OOM(vm, String::formatted("?{}", query.view()));
return TRY_OR_THROW_OOM(vm, String::formatted("?{}", *query));
}
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-hash