diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 4ec1d026f75..18fc4be7c46 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -454,14 +454,21 @@ FilePath FilePath::fromUrl(const QUrl &url) return fn; } +static QString hostEncoded(QString host) +{ + host.replace('%', "%25"); + host.replace('/', "%2f"); + return host; +} + /// \returns a QString for passing on to QString based APIs QString FilePath::toString() const { if (m_scheme.isEmpty()) return m_data; if (m_data.startsWith('/')) - return m_scheme + "://" + m_host + m_data; - return m_scheme + "://" + m_host + "/./" + m_data; + return m_scheme + "://" + hostEncoded(m_host) + m_data; + return m_scheme + "://" + hostEncoded(m_host) + "/./" + m_data; } QUrl FilePath::toUrl() const @@ -595,7 +602,6 @@ void FilePath::setScheme(const QString &scheme) void FilePath::setHost(const QString &host) { - QTC_CHECK(!host.contains('/')); m_host = host; } @@ -943,6 +949,8 @@ void FilePath::setFromString(const QString &filename) m_data = filename.mid(pos1); } else { m_host = filename.mid(pos1, pos2 - pos1); + m_host.replace("%2f", "/"); + m_host.replace("%25", "%"); m_data = filename.mid(pos2); } if (m_data.startsWith("/./")) diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index 501feff17b0..b3c035ea870 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -105,7 +105,6 @@ public: bool endsWith(const QString &s) const; bool exists() const; - bool needsDevice() const; FilePath parentDir() const; bool isChildOf(const FilePath &s) const; @@ -191,6 +190,13 @@ public: qint64 maxSize = -1, qint64 offset = 0) const; void asyncWriteFileContents(const Continuation &cont, const QByteArray &data) const; + // Prefer not to use + // Using needsDevice() in "user" code is likely to result in code that + // makes a local/remote distinction which should be avoided in general. + // There are usually other means available. E.g. distinguishing based + // on FilePath::osType(). + bool needsDevice() const; + // Deprecated. [[nodiscard]] static FilePath fromFileInfo(const QFileInfo &info); // Avoid. [[nodiscard]] QFileInfo toFileInfo() const; // Avoid. @@ -205,7 +211,7 @@ private: [[nodiscard]] QString mapToDevicePath() const; QString m_scheme; - QString m_host; + QString m_host; // May contain raw slashes. QString m_data; };