mirror of
https://github.com/RGBCube/serenity
synced 2025-07-29 12:17:36 +00:00
AK: Port URL::m_fragment from DeprecatedString to String
This commit is contained in:
parent
5663a2d3b4
commit
9d60f23abc
21 changed files with 68 additions and 76 deletions
24
AK/URL.cpp
24
AK/URL.cpp
|
@ -62,11 +62,6 @@ DeprecatedString URL::basename() const
|
|||
return percent_decode(last_segment);
|
||||
}
|
||||
|
||||
DeprecatedString URL::fragment() const
|
||||
{
|
||||
return m_fragment;
|
||||
}
|
||||
|
||||
// NOTE: This only exists for compatibility with the existing URL tests which check for both .is_null() and .is_empty().
|
||||
static DeprecatedString deprecated_string_percent_encode(DeprecatedString const& input, URL::PercentEncodeSet set = URL::PercentEncodeSet::Userinfo, URL::SpaceAsPlus space_as_plus = URL::SpaceAsPlus::No)
|
||||
{
|
||||
|
@ -135,11 +130,6 @@ void URL::append_path(StringView path)
|
|||
m_paths.append(deprecated_string_percent_encode(path, PercentEncodeSet::Path));
|
||||
}
|
||||
|
||||
void URL::set_fragment(StringView fragment)
|
||||
{
|
||||
m_fragment = fragment;
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port
|
||||
bool URL::cannot_have_a_username_or_password_or_port() const
|
||||
{
|
||||
|
@ -215,7 +205,8 @@ URL URL::create_with_file_scheme(DeprecatedString const& path, DeprecatedString
|
|||
url.set_paths(lexical_path.parts());
|
||||
if (path.ends_with('/'))
|
||||
url.append_slash();
|
||||
url.set_fragment(fragment);
|
||||
if (!fragment.is_null())
|
||||
url.set_fragment(String::from_deprecated_string(fragment).release_value_but_fixme_should_propagate_errors());
|
||||
return url;
|
||||
}
|
||||
|
||||
|
@ -232,7 +223,8 @@ URL URL::create_with_help_scheme(DeprecatedString const& path, DeprecatedString
|
|||
url.set_paths(lexical_path.parts());
|
||||
if (path.ends_with('/'))
|
||||
url.append_slash();
|
||||
url.set_fragment(fragment);
|
||||
if (!fragment.is_null())
|
||||
url.set_fragment(String::from_deprecated_string(fragment).release_value_but_fixme_should_propagate_errors());
|
||||
return url;
|
||||
}
|
||||
|
||||
|
@ -337,9 +329,9 @@ DeprecatedString URL::serialize(ExcludeFragment exclude_fragment) const
|
|||
}
|
||||
|
||||
// 6. If exclude fragment is false and url’s fragment is non-null, then append U+0023 (#), followed by url’s fragment, to output.
|
||||
if (exclude_fragment == ExcludeFragment::No && !m_fragment.is_null()) {
|
||||
if (exclude_fragment == ExcludeFragment::No && m_fragment.has_value()) {
|
||||
output.append('#');
|
||||
output.append(m_fragment);
|
||||
output.append(*m_fragment);
|
||||
}
|
||||
|
||||
// 7. Return output.
|
||||
|
@ -381,9 +373,9 @@ DeprecatedString URL::serialize_for_display() const
|
|||
builder.append(*m_query);
|
||||
}
|
||||
|
||||
if (!m_fragment.is_null()) {
|
||||
if (m_fragment.has_value()) {
|
||||
builder.append('#');
|
||||
builder.append(m_fragment);
|
||||
builder.append(*m_fragment);
|
||||
}
|
||||
|
||||
return builder.to_deprecated_string();
|
||||
|
|
6
AK/URL.h
6
AK/URL.h
|
@ -83,7 +83,7 @@ public:
|
|||
ErrorOr<String> serialized_host() const;
|
||||
DeprecatedString basename() const;
|
||||
Optional<String> const& query() const { return m_query; }
|
||||
DeprecatedString fragment() const;
|
||||
Optional<String> const& fragment() const { return m_fragment; }
|
||||
Optional<u16> port() const { return m_port; }
|
||||
DeprecatedString path_segment_at_index(size_t index) const;
|
||||
size_t path_segment_count() const { return m_paths.size(); }
|
||||
|
@ -102,7 +102,7 @@ public:
|
|||
void set_port(Optional<u16>);
|
||||
void set_paths(Vector<DeprecatedString> const&);
|
||||
void set_query(Optional<String> query) { m_query = move(query); }
|
||||
void set_fragment(StringView fragment);
|
||||
void set_fragment(Optional<String> fragment) { m_fragment = move(fragment); }
|
||||
void set_cannot_be_a_base_url(bool value) { m_cannot_be_a_base_url = value; }
|
||||
void append_path(StringView);
|
||||
void append_slash()
|
||||
|
@ -183,7 +183,7 @@ private:
|
|||
Optional<String> m_query;
|
||||
|
||||
// A URL’s fragment is either null or an ASCII string that can be used for further processing on the resource the URL’s other components identify. It is initially null.
|
||||
DeprecatedString m_fragment;
|
||||
Optional<String> m_fragment;
|
||||
|
||||
bool m_cannot_be_a_base_url { false };
|
||||
};
|
||||
|
|
|
@ -924,7 +924,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
|||
url->m_scheme = base_url->m_scheme;
|
||||
url->m_paths = base_url->m_paths;
|
||||
url->m_query = base_url->m_query;
|
||||
url->m_fragment = "";
|
||||
url->m_fragment = String {};
|
||||
url->m_cannot_be_a_base_url = true;
|
||||
state = State::Fragment;
|
||||
}
|
||||
|
@ -999,7 +999,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
|||
}
|
||||
// 3. Otherwise, if c is U+0023 (#), set url’s fragment to the empty string and state to fragment state.
|
||||
else if (code_point == '#') {
|
||||
url->m_fragment = "";
|
||||
url->m_fragment = String {};
|
||||
state = State::Fragment;
|
||||
}
|
||||
// 4. Otherwise, if c is not the EOF code point:
|
||||
|
@ -1309,7 +1309,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
|||
}
|
||||
// 3. Otherwise, if c is U+0023 (#), set url’s fragment to the empty string and state to fragment state.
|
||||
else if (code_point == '#') {
|
||||
url->m_fragment = "";
|
||||
url->m_fragment = String {};
|
||||
state = State::Fragment;
|
||||
}
|
||||
// 4. Otherwise, if c is not the EOF code point:
|
||||
|
@ -1450,7 +1450,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
|||
}
|
||||
// 3. Otherwise, if state override is not given and c is U+0023 (#), set url’s fragment to the empty string and state to fragment state.
|
||||
else if (!state_override.has_value() && code_point == '#') {
|
||||
url->m_fragment = "";
|
||||
url->m_fragment = String {};
|
||||
state = State::Fragment;
|
||||
}
|
||||
// 4. Otherwise, if c is not the EOF code point:
|
||||
|
@ -1519,7 +1519,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
|||
}
|
||||
// 7. If c is U+0023 (#), then set url’s fragment to the empty string and state to fragment state.
|
||||
else if (code_point == '#') {
|
||||
url->m_fragment = "";
|
||||
url->m_fragment = String {};
|
||||
state = State::Fragment;
|
||||
}
|
||||
}
|
||||
|
@ -1551,7 +1551,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
|||
else if (code_point == '#') {
|
||||
// NOTE: This needs to be percent decoded since the member variables contain decoded data.
|
||||
url->m_paths[0] = buffer.string_view();
|
||||
url->m_fragment = "";
|
||||
url->m_fragment = String {};
|
||||
buffer.clear();
|
||||
state = State::Fragment;
|
||||
}
|
||||
|
@ -1597,7 +1597,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
|||
|
||||
// 4. If c is U+0023 (#), then set url’s fragment to the empty string and state to fragment state.
|
||||
if (code_point == '#') {
|
||||
url->m_fragment = "";
|
||||
url->m_fragment = String {};
|
||||
state = State::Fragment;
|
||||
}
|
||||
}
|
||||
|
@ -1627,7 +1627,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
|||
// FIXME: 3. UTF-8 percent-encode c using the fragment percent-encode set and append the result to url’s fragment.
|
||||
buffer.append_code_point(code_point);
|
||||
} else {
|
||||
url->m_fragment = buffer.string_view();
|
||||
url->m_fragment = buffer.to_string().release_value_but_fixme_should_propagate_errors();
|
||||
buffer.clear();
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue