From 522ef53b981262a01c1cf91f963fd541c05b4330 Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Thu, 27 May 2021 21:40:02 +0200 Subject: [PATCH] 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. --- AK/URL.cpp | 50 ++++++++++++++++++-------------------------------- AK/URL.h | 1 - 2 files changed, 18 insertions(+), 33 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& 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(); diff --git a/AK/URL.h b/AK/URL.h index f7e1c0276d..85ab2f72d0 100644 --- a/AK/URL.h +++ b/AK/URL.h @@ -68,7 +68,6 @@ public: void set_password(const String&); void set_host(const String&); void set_port(const u16); - void set_path(const String&); void set_paths(const Vector&); void set_query(const String&); void set_fragment(const String&);