diff options
-rw-r--r-- | src/corelib/io/qstandardpaths_unix.cpp | 15 | ||||
-rw-r--r-- | tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 14 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index 10ca20629e..e2ed7c3766 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -259,10 +259,17 @@ static QStringList xdgDataDirs() dirs.append(QString::fromLatin1("/usr/local/share")); dirs.append(QString::fromLatin1("/usr/share")); } else { - dirs = xdgDataDirsEnv.split(QLatin1Char(':')); - // Normalize paths - for (int i = 0; i < dirs.count(); i++) - dirs[i] = QDir::cleanPath(dirs.at(i)); + dirs = xdgDataDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts); + + // Normalize paths, skip relative paths + QMutableListIterator<QString> it(dirs); + while (it.hasNext()) { + const QString dir = it.next(); + if (!dir.startsWith(QLatin1Char('/'))) + it.remove(); + else + it.setValue(QDir::cleanPath(dir)); + } // Remove duplicates from the list, there's no use for duplicated // paths in XDG_DATA_DIRS - if it's not found in the given diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 5c0485d228..4503f6fcbc 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -77,6 +77,7 @@ private slots: void testAllWritableLocations_data(); void testAllWritableLocations(); void testCleanPath(); + void testXdgPathCleanup(); private: #ifdef Q_XDG_PLATFORM @@ -491,6 +492,19 @@ void tst_qstandardpaths::testCleanPath() } } +void tst_qstandardpaths::testXdgPathCleanup() +{ +#ifdef Q_XDG_PLATFORM + setCustomLocations(); + const QString uncleanGlobalAppDir = "/./" + QFile::encodeName(m_globalAppDir); + qputenv("XDG_DATA_DIRS", QFile::encodeName(uncleanGlobalAppDir) + "::relative/path"); + const QStringList appsDirs = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation); + QVERIFY(!appsDirs.contains("/applications")); + QVERIFY(!appsDirs.contains(uncleanGlobalAppDir + "/applications")); + QVERIFY(!appsDirs.contains("relative/path/applications")); +#endif +} + QTEST_MAIN(tst_qstandardpaths) #include "tst_qstandardpaths.moc" |