From ba2956984c8b6c586ef06e1845132b9dca54e4ff Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 2 Sep 2022 16:47:54 +0200 Subject: [PATCH] Utils: Add a private FilePath::encodedHost() helper Change-Id: I7ce1c7e1e892b3a14f9d31e106b58e8340d574d8 Reviewed-by: Marcus Tillmanns Reviewed-by: hjk Reviewed-by: --- src/libs/utils/filepath.cpp | 11 ++++++----- src/libs/utils/filepath.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index a578d1a2988..9ea956669c0 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -172,8 +172,9 @@ FilePath FilePath::rootPath() return FilePath::fromString(QDir::rootPath()); } -static QString hostEncoded(QString host) +QString FilePath::encodedHost() const { + QString host = m_host; host.replace('%', "%25"); host.replace('/', "%2f"); return host; @@ -186,8 +187,8 @@ QString FilePath::toString() const return m_path; if (isRelativePath()) - return specialPath(SpecialPathComponent::RootPath) + "/" + m_scheme + "/" + hostEncoded(m_host) + "/./" + m_path; - return specialPath(SpecialPathComponent::RootPath) + "/" + m_scheme + "/" + hostEncoded(m_host) + m_path; + return specialPath(SpecialPathComponent::RootPath) + "/" + m_scheme + "/" + encodedHost() + "/./" + m_path; + return specialPath(SpecialPathComponent::RootPath) + "/" + m_scheme + "/" + encodedHost() + m_path; } QString FilePath::toFSPathString() const @@ -212,8 +213,8 @@ QString FilePath::toUserOutput() const { if (needsDevice()) { if (root().empty()) - return m_scheme + "://" + hostEncoded(m_host) + "/./" + m_path; - return m_scheme + "://" + hostEncoded(m_host) + m_path; + return m_scheme + "://" + encodedHost() + "/./" + m_path; + return m_scheme + "://" + encodedHost() + m_path; } QString tmp = toString(); diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index d47f2e0eccb..5458036c785 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -210,6 +210,7 @@ private: QStringView root() const; [[nodiscard]] QString mapToDevicePath() const; [[nodiscard]] QStringView pathWithoutRoot() const; + [[nodiscard]] QString encodedHost() const; QString m_scheme; QString m_host; // May contain raw slashes.