1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-29 12:17:36 +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

@ -62,11 +62,6 @@ DeprecatedString URL::basename() const
return percent_decode(last_segment);
}
DeprecatedString URL::query() const
{
return m_query;
}
DeprecatedString URL::fragment() const
{
return percent_decode(m_fragment);
@ -145,11 +140,6 @@ void URL::append_path(StringView path)
m_paths.append(deprecated_string_percent_encode(path, PercentEncodeSet::Path));
}
void URL::set_query(StringView query)
{
m_query = deprecated_string_percent_encode(query, is_special() ? PercentEncodeSet::SpecialQuery : PercentEncodeSet::Query);
}
void URL::set_fragment(StringView fragment)
{
m_fragment = deprecated_string_percent_encode(fragment, PercentEncodeSet::Fragment);
@ -346,9 +336,9 @@ DeprecatedString URL::serialize(ExcludeFragment exclude_fragment) const
}
// 5. If urls query is non-null, append U+003F (?), followed by urls query, to output.
if (!m_query.is_null()) {
if (m_query.has_value()) {
output.append('?');
output.append(m_query);
output.append(*m_query);
}
// 6. If exclude fragment is false and urls fragment is non-null, then append U+0023 (#), followed by urls fragment, to output.
@ -391,9 +381,9 @@ DeprecatedString URL::serialize_for_display() const
}
}
if (!m_query.is_null()) {
if (m_query.has_value()) {
builder.append('?');
builder.append(m_query);
builder.append(*m_query);
}
if (!m_fragment.is_null()) {

View file

@ -82,7 +82,7 @@ public:
Host const& host() const { return m_host; }
ErrorOr<String> serialized_host() const;
DeprecatedString basename() const;
DeprecatedString query() const;
Optional<String> const& query() const { return m_query; }
// NOTE: fragment() is percent-decoded, raw_fragment() is not.
DeprecatedString fragment() const;
DeprecatedString raw_fragment() const;
@ -103,7 +103,7 @@ public:
void set_host(Host);
void set_port(Optional<u16>);
void set_paths(Vector<DeprecatedString> const&);
void set_query(StringView);
void set_query(Optional<String> query) { m_query = move(query); }
void set_fragment(StringView fragment);
void set_cannot_be_a_base_url(bool value) { m_cannot_be_a_base_url = value; }
void append_path(StringView);
@ -182,7 +182,7 @@ private:
Vector<DeprecatedString> m_paths;
// A URLs query is either null or an ASCII string. It is initially null.
DeprecatedString m_query;
Optional<String> m_query;
// A URLs fragment is either null or an ASCII string that can be used for further processing on the resource the URLs other components identify. It is initially null.
DeprecatedString m_fragment;

View file

@ -994,7 +994,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
// 2. If c is U+003F (?), then set urls query to the empty string, and state to query state.
if (code_point == '?') {
url->m_query = "";
url->m_query = String {};
state = State::Query;
}
// 3. Otherwise, if c is U+0023 (#), set urls fragment to the empty string and state to fragment state.
@ -1304,7 +1304,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
// 2. If c is U+003F (?), then set urls query to the empty string and state to query state.
if (code_point == '?') {
url->m_query = "";
url->m_query = String {};
state = State::Query;
}
// 3. Otherwise, if c is U+0023 (#), set urls fragment to the empty string and state to fragment state.
@ -1445,7 +1445,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
}
// 2. Otherwise, if state override is not given and c is U+003F (?), set urls query to the empty string and state to query state.
else if (!state_override.has_value() && code_point == '?') {
url->m_query = "";
url->m_query = String {};
state = State::Query;
}
// 3. Otherwise, if state override is not given and c is U+0023 (#), set urls fragment to the empty string and state to fragment state.
@ -1514,7 +1514,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
// 6. If c is U+003F (?), then set urls query to the empty string and state to query state.
if (code_point == '?') {
url->m_query = "";
url->m_query = String {};
state = State::Query;
}
// 7. If c is U+0023 (#), then set urls fragment to the empty string and state to fragment state.
@ -1543,7 +1543,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
// 1. If c is U+003F (?), then set urls query to the empty string and state to query state.
if (code_point == '?') {
url->m_paths[0] = buffer.string_view();
url->m_query = "";
url->m_query = String {};
buffer.clear();
state = State::Query;
}
@ -1584,14 +1584,13 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
// * c is the EOF code point
if ((!state_override.has_value() && code_point == '#')
|| code_point == end_of_file) {
VERIFY(url->m_query == "");
// then:
// 1. Let queryPercentEncodeSet be the special-query percent-encode set if url is special; otherwise the query percent-encode set.
auto query_percent_encode_set = url->is_special() ? URL::PercentEncodeSet::SpecialQuery : URL::PercentEncodeSet::Query;
// 2. Percent-encode after encoding, with encoding, buffer, and queryPercentEncodeSet, and append the result to urls query.
url->m_query = percent_encode_after_encoding(buffer.string_view(), query_percent_encode_set);
url->m_query = String::from_deprecated_string(percent_encode_after_encoding(buffer.string_view(), query_percent_encode_set)).release_value_but_fixme_should_propagate_errors();
// 3. Set buffer to the empty string.
buffer.clear();