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>bb10
parent
24d06c8c3c
commit
6f66205bac
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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/")
|
||||
|
|
|
|||
Loading…
Reference in New Issue