summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2014-11-17 11:48:08 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2014-11-17 21:47:29 +0100
commit6f66205bacec923d989fa129796d5bd7e3786e4d (patch)
tree8ef3120c1a0007d617de4e168072506a20319d7f
parent24d06c8c3cdabb080f13940bd38e324659b402d0 (diff)
Add Windows-specific notation for WebDAV to QUrl.
Convert a Windows-specific WebDAV specification "//host@SSL/path" into URL's with scheme set to "webdavs" and back to local file (Windows only). Task-number: QTBUG-42346 Change-Id: I12663243848ea7b2d3f208743e837e9de14a93eb Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/io/qurl.cpp41
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp9
2 files changed, 44 insertions, 6 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index d4c5e03058..686050fa49 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -429,6 +429,16 @@ static inline QString fileScheme()
return QStringLiteral("file");
}
+static inline QString webDavScheme()
+{
+ return QStringLiteral("webdavs");
+}
+
+static inline QString webDavSslTag()
+{
+ return QStringLiteral("@SSL");
+}
+
#ifdef Q_COMPILER_CLASS_ENUM
# define colon_uchar : uchar
#else
@@ -992,10 +1002,15 @@ inline bool QUrlPrivate::setScheme(const QString &value, int len, bool doSetErro
}
// did we set to the file protocol?
- if (scheme == fileScheme())
+ if (scheme == fileScheme()
+#ifdef Q_OS_WIN
+ || scheme == webDavScheme()
+#endif
+ ) {
flags |= IsLocalFile;
- else
+ } else {
flags &= ~IsLocalFile;
+ }
return true;
}
@@ -3738,7 +3753,7 @@ QUrl QUrl::fromLocalFile(const QString &localFile)
QUrl url;
if (localFile.isEmpty())
return url;
- url.setScheme(fileScheme());
+ QString scheme = fileScheme();
QString deslashified = QDir::fromNativeSeparators(localFile);
// magic for drives on windows
@@ -3747,13 +3762,21 @@ QUrl QUrl::fromLocalFile(const QString &localFile)
} else if (deslashified.startsWith(QLatin1String("//"))) {
// magic for shared drive on windows
int indexOfPath = deslashified.indexOf(QLatin1Char('/'), 2);
- url.setHost(deslashified.mid(2, indexOfPath - 2));
+ QString hostSpec = deslashified.mid(2, indexOfPath - 2);
+ // Check for Windows-specific WebDAV specification: "//host@SSL/path".
+ if (hostSpec.endsWith(webDavSslTag(), Qt::CaseInsensitive)) {
+ hostSpec.chop(4);
+ scheme = webDavScheme();
+ }
+ url.setHost(hostSpec);
+
if (indexOfPath > 2)
deslashified = deslashified.right(deslashified.length() - indexOfPath);
else
deslashified.clear();
}
+ url.setScheme(scheme);
url.setPath(deslashified, DecodedMode);
return url;
}
@@ -3783,8 +3806,14 @@ QString QUrl::toLocalFile() const
// magic for shared drive on windows
if (!d->host.isEmpty()) {
- tmp = QStringLiteral("//") + host() + (ourPath.length() > 0 && ourPath.at(0) != QLatin1Char('/')
- ? QLatin1Char('/') + ourPath : ourPath);
+ 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
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 5b5161e24a..6d801f75c1 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -1179,6 +1179,12 @@ void tst_QUrl::toLocalFile_data()
QTest::newRow("data0") << QString::fromLatin1("file:/a.txt") << QString::fromLatin1("/a.txt");
QTest::newRow("data4") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt");
+ QTest::newRow("data4a") << QString::fromLatin1("webdavs://somewebdavhost/somedir/somefile")
+#ifdef Q_OS_WIN // QTBUG-42346, WebDAV is visible as local file on Windows only.
+ << QString::fromLatin1("//somewebdavhost@SSL/somedir/somefile");
+#else
+ << QString();
+#endif
#ifdef Q_OS_WIN
QTest::newRow("data5") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("c:/a.txt");
#else
@@ -1227,6 +1233,9 @@ void tst_QUrl::fromLocalFile_data()
QTest::newRow("data3") << QString::fromLatin1("c:/a.txt") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("/c:/a.txt");
QTest::newRow("data4") << QString::fromLatin1("//somehost/somedir/somefile") << QString::fromLatin1("file://somehost/somedir/somefile")
<< QString::fromLatin1("/somedir/somefile");
+ QTest::newRow("data4a") << QString::fromLatin1("//somewebdavhost@SSL/somedir/somefile")
+ << QString::fromLatin1("webdavs://somewebdavhost/somedir/somefile")
+ << QString::fromLatin1("/somedir/somefile");
QTest::newRow("data5") << QString::fromLatin1("//somehost") << QString::fromLatin1("file://somehost")
<< QString::fromLatin1("");
QTest::newRow("data6") << QString::fromLatin1("//somehost/") << QString::fromLatin1("file://somehost/")