From 101449a4cfa9c0d216332c6dc8ba826e8109e09d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 8 Jul 2016 15:30:45 +0200 Subject: QDir::cd(): Handle UNC server paths correctly Add a bool *ok out parameter to qt_normalizePathSegments() and return false when ".." are left over for an absolute path, indicating an attempt to change above root. Factor out static helper qt_cleanPath() to be able to pass the return value to QDir::cd() and return on failure from there. Amends change 63f634322b2c0f795bd424be9e51953a10c701de, which did not handle UNC paths. Task-number: QTBUG-53712 Change-Id: I3e63a5dd0259306a0b99145348d815899582f78e Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qdir/tst_qdir.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index fe12850476..b86c6e4dfa 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -58,7 +58,8 @@ #ifdef QT_BUILD_INTERNAL QT_BEGIN_NAMESPACE -extern Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &, bool); +extern Q_AUTOTEST_EXPORT QString + qt_normalizePathSegments(const QString &path, bool allowUncPaths, bool *ok = nullptr); QT_END_NAMESPACE #endif @@ -2246,6 +2247,10 @@ void tst_QDir::cdBelowRoot_data() const QString systemRoot = QString::fromLocal8Bit(qgetenv("SystemRoot")); QTest::newRow("windows-drive") << systemDrive << systemRoot.mid(3) << QDir::cleanPath(systemRoot); + const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); + const QString testDirectory = QStringLiteral("testshare"); + QTest::newRow("windows-share") + << uncRoot << testDirectory << QDir::cleanPath(uncRoot + QLatin1Char('/') + testDirectory); #endif // Windows } -- cgit v1.2.3