From a027f1cfcede0c404991416f831c57dd5cd9bed3 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 20 Jun 2017 11:47:36 +0200 Subject: CMake: Only handle strings at start of line Allow comments at the start of line only (or after only space characters) in CMakeCache.txt-style lines. Task-number: QTCREATORBUG-18385 Change-Id: I8b69144ea4f6a667ae1df382c8c4c1e88eca799b Reviewed-by: Eike Ziller Reviewed-by: Tim Jenssen --- src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp b/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp index 2b09a3769c..258803d45e 100644 --- a/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp @@ -170,15 +170,20 @@ std::function CMakeCo CMakeConfigItem CMakeConfigItem::fromString(const QString &s) { - // Strip comments: + // Strip comments (only at start of line!): int commentStart = s.count(); - int pos = s.indexOf(QLatin1Char('#')); - if (pos >= 0) - commentStart = pos; - pos = s.indexOf(QLatin1String("//")); - if (pos >= 0 && pos < commentStart) - commentStart = pos; - + for (int i = 0; i < s.count(); ++i) { + const QChar c = s.at(i); + if (c == ' ' || c == '\t') + continue; + else if ((c == '#') + || (c == '/' && i < s.count() - 1 && s.at(i + 1) == '/')) { + commentStart = i; + break; + } else { + break; + } + } const QString line = s.mid(0, commentStart); // Split up line: -- cgit v1.2.1