diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-01-29 21:47:25 +0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2023-02-01 19:46:02 +0000 |
commit | d4f72b4de63fe0622908c7657f9724bad359574e (patch) | |
tree | dda7735656ad5bf6539f4e36587adc02ebead56c /tests | |
parent | 1f1380b79cc63349da353052e8b6c5c923059975 (diff) |
QStandardPaths/unix: ignore relative paths in all $XDG_* env vars
This is a continuation of commit 5c9d671bfb5b511106.
[ChangeLog][QtCore][QStandardPaths] Improved conformance to the
Freedesktop basedir spec by ignoring any relative paths in XDG_*
environment variables.
Fixes: QTBUG-58043
Change-Id: I7c34143ced97d6d3de6ecbf13bccf9e935462d1e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 8f96f1d49b..444af8f9f6 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -24,6 +24,8 @@ #define Q_XDG_PLATFORM #endif +using namespace Qt::StringLiterals; + // Update this when adding new enum values; update enumNames too static const int MaxStandardLocation = QStandardPaths::AppConfigLocation; @@ -724,6 +726,31 @@ void tst_qstandardpaths::testXdgPathCleanup() QVERIFY(!appsDirs.contains("/applications")); QVERIFY(!appsDirs.contains(uncleanGlobalAppDir + "/applications")); QVERIFY(!appsDirs.contains("relative/path/applications")); + + const QString uncleanGlobalConfigDir = "/./" + QFile::encodeName(m_globalConfigDir); + qputenv("XDG_CONFIG_DIRS", QFile::encodeName(uncleanGlobalConfigDir) + "::relative/path"); + const QStringList configDirs = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation); + QVERIFY(!configDirs.contains("relative/path"_L1)); + QVERIFY(!configDirs.contains(""_L1)); + + // Relative paths in XDG_* env vars are ignored + const QString relative("./someRelativeDir"); + + qputenv("XDG_CACHE_HOME", relative.toLatin1()); + const QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); + QCOMPARE_NE(cacheDir, relative); + + qputenv("XDG_DATA_HOME", relative.toLatin1()); + const QString localDataDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); + QCOMPARE_NE(localDataDir, relative); + + qputenv("XDG_CONFIG_HOME", relative.toLatin1()); + const QString localConfig = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); + QCOMPARE_NE(localConfig, relative); + + qputenv("XDG_RUNTIME_DIR", relative.toLatin1()); + const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); + QCOMPARE_NE(runtimeDir, relative); #endif } |