mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 07:37:35 +00:00
AK: Port URL::m_query from DeprecatedString to String
This commit is contained in:
parent
55a01e72ca
commit
21fe86d235
14 changed files with 63 additions and 75 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -50,8 +50,6 @@ static Optional<AK::URL> parse_api_url(String const& url, Optional<String> const
|
|||
// https://url.spec.whatwg.org/#dom-url-url
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::construct_impl(JS::Realm& realm, String const& url, Optional<String> const& base)
|
||||
{
|
||||
auto& vm = realm.vm();
|
||||
|
||||
// 1. Let parsedURL be the result of running the API URL parser on url with base, if given.
|
||||
auto parsed_url = parse_api_url(url, base);
|
||||
|
||||
|
@ -60,7 +58,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::construct_impl(JS::Realm& realm,
|
|||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid URL"sv };
|
||||
|
||||
// 3. Let query be parsedURL’s query, if that is non-null, and the empty string otherwise.
|
||||
auto query = parsed_url->query().is_null() ? String {} : TRY_OR_THROW_OOM(vm, String::from_deprecated_string(parsed_url->query()));
|
||||
auto query = parsed_url->query().value_or(String {});
|
||||
|
||||
// 4. Set this’s URL to parsedURL.
|
||||
// 5. Set this’s query object to a new URLSearchParams object.
|
||||
|
@ -182,8 +180,8 @@ WebIDL::ExceptionOr<void> URL::set_href(String const& href)
|
|||
auto query = m_url.query();
|
||||
|
||||
// 6. If query is non-null, then set this’s query object’s list to the result of parsing query.
|
||||
if (!query.is_null())
|
||||
m_query->m_list = TRY_OR_THROW_OOM(vm, url_decode(query));
|
||||
if (query.has_value())
|
||||
m_query->m_list = TRY_OR_THROW_OOM(vm, url_decode(*query));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -382,11 +380,11 @@ WebIDL::ExceptionOr<String> URL::search() const
|
|||
auto& vm = realm().vm();
|
||||
|
||||
// 1. If this’s URL’s query is either null or the empty string, then return the empty string.
|
||||
if (m_url.query().is_null() || m_url.query().is_empty())
|
||||
if (!m_url.query().has_value() || m_url.query()->is_empty())
|
||||
return String {};
|
||||
|
||||
// 2. Return U+003F (?), followed by this’s URL’s query.
|
||||
return TRY_OR_THROW_OOM(vm, String::formatted("?{}", m_url.query()));
|
||||
return TRY_OR_THROW_OOM(vm, String::formatted("?{}", *m_url.query()));
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#ref-for-dom-url-search%E2%91%A0
|
||||
|
@ -417,7 +415,7 @@ WebIDL::ExceptionOr<void> URL::set_search(String const& search)
|
|||
|
||||
// 4. Set url’s query to the empty string.
|
||||
auto url_copy = 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 {});
|
||||
|
||||
// 5. Basic URL parse input with url as url and query state as state override.
|
||||
auto result_url = URLParser::basic_parse(input, {}, move(url_copy), URLParser::State::Query);
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
|
||||
WebIDL::ExceptionOr<String> to_json() const;
|
||||
|
||||
void set_query(Badge<URLSearchParams>, StringView query) { m_url.set_query(query); }
|
||||
void set_query(Badge<URLSearchParams>, Optional<String> query) { m_url.set_query(move(query)); }
|
||||
|
||||
private:
|
||||
URL(JS::Realm&, AK::URL, JS::NonnullGCPtr<URLSearchParams> query);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue