summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorKevin Funk <kevin.funk@kdab.com>2016-01-14 23:33:28 +0100
committerDominik Haumann <dhaumann@kde.org>2016-01-20 13:24:53 +0000
commit8dad3bf2121e3ad5e405665fefa28c4d53192bf7 (patch)
treeda4bfa3c97d13eaf629431ee0916206f09e2525d /src/corelib/io
parentb530ca770f54165cd2766ccebb7269ba45bccb51 (diff)
Fix toDisplayString(QUrl::PreferLocalFile) on Win
When using QUrl::PreferLocalFile we do want to strip the leading slash, as toLocalFile() would do as well. Behavior change by means of an example: QUrl url(QUrl::fromLocalFile("C:/file.txt") url.toLocalFile() --> "C:/file.txt" Before: url.toDisplayString(QUrl::PreferLocalFile) --> "/C:/file.txt" After: url.toDisplayString(QUrl::PreferLocalFile) --> "C:/file.txt" Task-number: QTBUG-41729 Change-Id: I7d425541f6077ebcf3fcf46feeb7e0f03a0d7fe2 Reviewed-by: Dominik Haumann <dhaumann@kde.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qurl.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 775a870a27..b51119c7ad 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -556,6 +556,7 @@ public:
inline bool hasFragment() const { return sectionIsPresent & Fragment; }
inline bool isLocalFile() const { return flags & IsLocalFile; }
+ QString toLocalFile(QUrl::FormattingOptions options) const;
QString mergePaths(const QString &relativePath) const;
@@ -1460,6 +1461,33 @@ inline void QUrlPrivate::parse(const QString &url, QUrl::ParsingMode parsingMode
validateComponent(Fragment, url, hash + 1, len);
}
+QString QUrlPrivate::toLocalFile(QUrl::FormattingOptions options) const
+{
+ QString tmp;
+ QString ourPath;
+ appendPath(ourPath, options, QUrlPrivate::Path);
+
+ // magic for shared drive on windows
+ if (!host.isEmpty()) {
+ tmp = QStringLiteral("//") + host;
+#ifdef Q_OS_WIN // QTBUG-42346, WebDAV is visible as local file on Windows only.
+ if (scheme == webDavScheme())
+ tmp += webDavSslTag();
+#endif
+ if (!ourPath.isEmpty() && !ourPath.startsWith(QLatin1Char('/')))
+ tmp += QLatin1Char('/');
+ tmp += ourPath;
+ } else {
+ tmp = ourPath;
+#ifdef Q_OS_WIN
+ // magic for drives on windows
+ if (ourPath.length() > 2 && ourPath.at(0) == QLatin1Char('/') && ourPath.at(2) == QLatin1Char(':'))
+ tmp.remove(0, 1);
+#endif
+ }
+ return tmp;
+}
+
/*
From http://www.ietf.org/rfc/rfc3986.txt, 5.2.3: Merge paths
@@ -3257,7 +3285,7 @@ QString QUrl::toString(FormattingOptions options) const
&& (!d->hasQuery() || options.testFlag(QUrl::RemoveQuery))
&& (!d->hasFragment() || options.testFlag(QUrl::RemoveFragment))
&& isLocalFile()) {
- return path(options);
+ return d->toLocalFile(options);
}
QString url;
@@ -3820,28 +3848,7 @@ QString QUrl::toLocalFile() const
if (!isLocalFile())
return QString();
- QString tmp;
- QString ourPath = path(QUrl::FullyDecoded);
-
- // magic for shared drive on windows
- if (!d->host.isEmpty()) {
- tmp = QStringLiteral("//") + host();
-#ifdef Q_OS_WIN // QTBUG-42346, WebDAV is visible as local file on Windows only.
- if (scheme() == webDavScheme())
- tmp += webDavSslTag();
-#endif
- if (!ourPath.isEmpty() && !ourPath.startsWith(QLatin1Char('/')))
- tmp += QLatin1Char('/');
- tmp += ourPath;
- } else {
- tmp = ourPath;
-#ifdef Q_OS_WIN
- // magic for drives on windows
- if (ourPath.length() > 2 && ourPath.at(0) == QLatin1Char('/') && ourPath.at(2) == QLatin1Char(':'))
- tmp.remove(0, 1);
-#endif
- }
- return tmp;
+ return d->toLocalFile(QUrl::FullyDecoded);
}
/*!