diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-05-27 21:40:02 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-01 09:28:05 +0200 |
commit | 522ef53b981262a01c1cf91f963fd541c05b4330 (patch) | |
tree | bf04d9db795ab77ef9d7d9fa2a3e0c25907a3cf2 /AK/URL.cpp | |
parent | b7c6af0a041376ec6bfe4136f4ec0cded9ff0560 (diff) | |
download | serenity-522ef53b981262a01c1cf91f963fd541c05b4330.zip |
AK: Remove deprecated m_path member variable from URL
The m_path member variable has been superseded by m_paths. Thus, it has
been removed. The path() getter will continue to exist as a convenience
method for getting the path joined together as a string.
Diffstat (limited to 'AK/URL.cpp')
-rw-r--r-- | AK/URL.cpp | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/AK/URL.cpp b/AK/URL.cpp index 8288f7abe6..2d69ace1d4 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -50,8 +50,6 @@ String URL::path() const { if (cannot_be_a_base_url()) return paths()[0]; - if (!m_path.is_null()) - return m_path; StringBuilder builder; for (auto& path : m_paths) { builder.append('/'); @@ -102,12 +100,6 @@ void URL::set_port(const u16 port) m_valid = compute_validity(); } -void URL::set_path(const String& path) -{ - m_path = path; - m_valid = compute_validity(); -} - void URL::set_paths(const Vector<String>& paths) { m_paths = paths; @@ -180,9 +172,16 @@ u16 URL::default_port_for_scheme(const StringView& scheme) URL URL::create_with_file_scheme(const String& path, const String& fragment) { + LexicalPath lexical_path(path); + if (!lexical_path.is_valid() || !lexical_path.is_absolute()) + return {}; URL url; url.set_scheme("file"); - url.set_path(path); + url.set_host(String::empty()); + url.set_paths(lexical_path.parts()); + // NOTE: To indicate that we want to end the path with a slash, we have to append an empty path segment. + if (path.ends_with('/')) + url.append_path(""); url.set_fragment(fragment); return url; } @@ -262,16 +261,11 @@ String URL::serialize(ExcludeFragment exclude_fragment) const if (cannot_be_a_base_url()) { builder.append(percent_encode(m_paths[0], PercentEncodeSet::Path)); } else { - // FIXME: Temporary m_path hack - if (!m_path.is_null()) { - builder.append(path()); - } else { - if (m_host.is_null() && m_paths.size() > 1 && m_paths[0].is_empty()) - builder.append("/."); - for (auto& segment : m_paths) { - builder.append('/'); - builder.append(percent_encode(segment, PercentEncodeSet::Path)); - } + if (m_host.is_null() && m_paths.size() > 1 && m_paths[0].is_empty()) + builder.append("/."); + for (auto& segment : m_paths) { + builder.append('/'); + builder.append(percent_encode(segment, PercentEncodeSet::Path)); } } @@ -311,16 +305,11 @@ String URL::serialize_for_display() const if (cannot_be_a_base_url()) { builder.append(percent_encode(m_paths[0], PercentEncodeSet::Path)); } else { - // FIXME: Temporary m_path hack - if (!m_path.is_null()) { - builder.append(path()); - } else { - if (m_host.is_null() && m_paths.size() > 1 && m_paths[0].is_empty()) - builder.append("/."); - for (auto& segment : m_paths) { - builder.append('/'); - builder.append(percent_encode(segment, PercentEncodeSet::Path)); - } + if (m_host.is_null() && m_paths.size() > 1 && m_paths[0].is_empty()) + builder.append("/."); + for (auto& segment : m_paths) { + builder.append('/'); + builder.append(percent_encode(segment, PercentEncodeSet::Path)); } } @@ -348,9 +337,6 @@ String URL::basename() const { if (!m_valid) return {}; - // FIXME: Temporary m_path hack - if (!m_path.is_null()) - return LexicalPath(m_path).basename(); if (m_paths.is_empty()) return {}; return m_paths.last(); |