From 4474d26443470ffda13f8d476135546782ad9a75 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 30 Jul 2023 17:58:35 +0000 Subject: [PATCH] partially revert a551f78d117b1e576aab029a9b04feb1c47c7d65 fixes Plasma::RunnerContext test failure Signed-off-by: Ivailo Monev --- src/core/io/qurl.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/core/io/qurl.cpp b/src/core/io/qurl.cpp index 431e56523..c89c85da0 100644 --- a/src/core/io/qurl.cpp +++ b/src/core/io/qurl.cpp @@ -3196,7 +3196,15 @@ QUrl QUrl::fromLocalFile(const QString &localFile) { QUrl url; url.setScheme(QLatin1String("file")); - url.setPath(localFile); + // magic for authority path-abempty + if (localFile.startsWith(QLatin1String("//"))) { + int indexOfPath = localFile.indexOf(QLatin1Char('/'), 2); + url.setHost(localFile.mid(2, indexOfPath - 2)); + if (indexOfPath > 2) + url.setPath(localFile.right(localFile.length() - indexOfPath)); + } else { + url.setPath(localFile); + } return url; } @@ -3205,6 +3213,10 @@ QUrl QUrl::fromLocalFile(const QString &localFile) returned will use forward slashes, even if it was originally created from one with backslashes. + If this URL contains a non-empty hostname, it will be encoded in the + returned value in the form found on SMB networks (for example, + "//servername/path/to/file.txt"). + If this is a relative URL, in Qt 4.x this function returns the path to maintain backward compatability. This will change from 5.0 onwards. Then the path is returned only for URLs where the scheme is "file", and for @@ -3220,7 +3232,20 @@ QString QUrl::toLocalFile() const if (!isLocalFile() && !scheme().isEmpty()) return QString(); - return path(); + QString tmp; + QString ourPath = path(); + + QMutexLocker lock(&d->mutex); // for d->host + + // magic for authority path-abempty + if (!d->host.isEmpty()) { + tmp = QLatin1String("//") + d->host + (ourPath.length() > 0 && ourPath.at(0) != QLatin1Char('/') + ? QLatin1Char('/') + ourPath : ourPath); + } else { + tmp = ourPath; + } + + return tmp; } /*! -- 2.11.0