aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/stringutils.cpp
diff options
context:
space:
mode:
authorDaniel Teske <daniel.teske@theqtcompany.com>2014-12-05 12:23:00 +0100
committerDaniel Teske <daniel.teske@theqtcompany.com>2014-12-10 11:52:21 +0100
commite815f48f17e99315857c87a1b18e8de896dbbecf (patch)
tree8d128dab1d71361367e8cb0853565913de3bec96 /src/libs/utils/stringutils.cpp
parent1f48f7205dda69b89acdc56dd1303b300ac1945a (diff)
Utils: Fix bug in commonPath() with directories
The algorithm expected a list of filenames, but the cmake plugin passed in a list containing a directory and a filename. Appending a slash to each entry. (Except root entries.) fixes this. Task-number: QTCREATORBUG-13606 Change-Id: I518a2601295017636f4c450cc8a9026f4b41689a Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Diffstat (limited to 'src/libs/utils/stringutils.cpp')
-rw-r--r--src/libs/utils/stringutils.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libs/utils/stringutils.cpp b/src/libs/utils/stringutils.cpp
index da0c0ab59eb..179a4d8a61d 100644
--- a/src/libs/utils/stringutils.cpp
+++ b/src/libs/utils/stringutils.cpp
@@ -32,6 +32,8 @@
#include "hostosinfo.h"
+#include <utils/algorithm.h>
+
#include <QDir>
#include <limits.h>
@@ -87,7 +89,12 @@ QTCREATOR_UTILS_EXPORT QString commonPrefix(const QStringList &strings)
QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files)
{
- QString common = commonPrefix(files);
+ QStringList appendedSlashes = Utils::transform(files, [](const QString &file) -> QString {
+ if (!file.endsWith(QLatin1Char('/')))
+ return QString(file + QLatin1Char('/'));
+ return file;
+ });
+ QString common = commonPrefix(appendedSlashes);
// Find common directory part: "C:\foo\bar" -> "C:\foo"
int lastSeparatorPos = common.lastIndexOf(QLatin1Char('/'));
if (lastSeparatorPos == -1)