summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2014-02-07 11:20:58 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-10 11:00:41 +0100
commit5c9d671bfb5b5111069aadc9bf3f742f369c74ae (patch)
tree3ff758089963ad4552604206c42b9138e6321cc7 /src/corelib/io
parent4965cf78c1d9800944cec53babcf6be1cadf5940 (diff)
QStandardPaths: fix empty path in XDG_DATA_DIRS being treated as '/'.
The basedir xdg spec says: "All paths set in these environment variables must be absolute. If an implementation encounters a relative path in any of these variables it should consider the path invalid and ignore it." Therefore we ignore relative paths including the empty string. Change-Id: I8f779b78981018051b16de23b2514f2e62b7ab39 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp15
1 files changed, 11 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