diff --git a/src/libs/utils/templateengine.cpp b/src/libs/utils/templateengine.cpp index ff3f01d075b..b76d42d6314 100644 --- a/src/libs/utils/templateengine.cpp +++ b/src/libs/utils/templateengine.cpp @@ -139,6 +139,7 @@ bool PreprocessContext::process(const QString &in, QString *out, QString *errorM const QChar newLine = QLatin1Char('\n'); const QStringList lines = in.split(newLine, QString::KeepEmptyParts); const int lineCount = lines.size(); + bool first = true; for (int l = 0; l < lineCount; l++) { // Check for element of the stack (be it dummy, else something is wrong). if (m_sectionStack.isEmpty()) { @@ -206,7 +207,9 @@ bool PreprocessContext::process(const QString &in, QString *out, QString *errorM break; case OtherSection: // Rest: Append according to current condition. if (top.condition) { - if (l != 0) + if (first) + first = false; + else out->append(newLine); out->append(lines.at(l)); } diff --git a/tests/auto/utils/templateengine/tst_templateengine.cpp b/tests/auto/utils/templateengine/tst_templateengine.cpp index e301e3f77a5..ed51e5330af 100644 --- a/tests/auto/utils/templateengine/tst_templateengine.cpp +++ b/tests/auto/utils/templateengine/tst_templateengine.cpp @@ -45,15 +45,15 @@ void tst_TemplateEngine::testTemplateEngine_data() QTest::addColumn("expectedErrorMessage"); QTest::newRow("if") << QString::fromLatin1("@if 1\nline 1\n@elsif 0\nline 2\n@else\nline 3\n@endif\n") - << QString::fromLatin1("line 1\n\n") + << QString::fromLatin1("line 1\n") << QString(); QTest::newRow("elsif") << QString::fromLatin1("@if 0\nline 1\n@elsif 1\nline 2\n@else\nline 3\n@endif\n") - << QString::fromLatin1("line 2\n\n") + << QString::fromLatin1("line 2\n") << QString(); QTest::newRow("else") << QString::fromLatin1("@if 0\nline 1\n@elsif 0\nline 2\n@else\nline 3\n@endif\n") - << QString::fromLatin1("line 3\n\n") + << QString::fromLatin1("line 3\n") << QString(); QTest::newRow("nested-if") << QString::fromLatin1("@if 1\n" @@ -61,7 +61,7 @@ void tst_TemplateEngine::testTemplateEngine_data() "@else\n" " @if 1\nline 4\n@elsif 0\nline 5\n@else\nline 6\n@endif\n" "@endif\n") - << QString::fromLatin1("line 1\n\n") + << QString::fromLatin1("line 1\n") << QString(); QTest::newRow("nested-else") << QString::fromLatin1("@if 0\n" @@ -69,7 +69,7 @@ void tst_TemplateEngine::testTemplateEngine_data() "@else\n" " @if 1\nline 4\n@elsif 0\nline 5\n@else\nline 6\n@endif\n" "@endif\n") - << QString::fromLatin1("line 4\n\n") + << QString::fromLatin1("line 4\n") << QString(); QTest::newRow("twice-nested-if") << QString::fromLatin1("@if 0\n" @@ -81,7 +81,7 @@ void tst_TemplateEngine::testTemplateEngine_data() " @if 1\nline 3\n@else\nline 4\n@endif\n" " @endif\n" "@endif\n") - << QString::fromLatin1("line 3\n\n") + << QString::fromLatin1("line 3\n") << QString(); }