From 83c3b2cad0d9387d4918dae970693bda7aa54966 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 5 Dec 2018 15:03:30 +0100 Subject: Fix handling of a double backslash at the end of line The double backslash at EOL shall not be altered. Task-number: QTCREATORBUG-20550 Change-Id: Ib4cc73da7a6634233d222945f01dd7974d112971 Reviewed-by: Oliver Wolff --- src/jomlib/makefilelinereader.cpp | 4 ++++ tests/makefiles/macrotest.mk | 1 + tests/tests.cpp | 1 + 3 files changed, 6 insertions(+) diff --git a/src/jomlib/makefilelinereader.cpp b/src/jomlib/makefilelinereader.cpp index 60a1cbf..ee20d86 100644 --- a/src/jomlib/makefilelinereader.cpp +++ b/src/jomlib/makefilelinereader.cpp @@ -139,6 +139,8 @@ MakefileLine MakefileLineReader::readLine_impl_local8bit() if (bufLength >= 3 && buf[bufLength - 3] == '^') { buf[bufLength - 3] = '\\'; // replace "^\\\n" -> "\\\\\n" bufLength -= 2; // remove "\\\n" + } else if (bufLength >= 3 && buf[bufLength - 3] == '\\') { + bufLength--; // remove trailing \n } else { bufLength -= 2; // remove "\\\n" line.continuation = LineContinuationType::Backslash; @@ -172,6 +174,8 @@ MakefileLine MakefileLineReader::readLine_impl_unicode() if (str.endsWith(QLatin1String("^\\"))) { str.remove(str.length() - 2, 1); + } else if (str.endsWith(QLatin1String("\\\\"))) { + // Do nothing. Double backslash at the end is not altered. } else if (str.endsWith(QLatin1Char('\\'))) { str.chop(1); line.continuation = LineContinuationType::Backslash; diff --git a/tests/makefiles/macrotest.mk b/tests/makefiles/macrotest.mk index 18db82d..eabeacb 100644 --- a/tests/makefiles/macrotest.mk +++ b/tests/makefiles/macrotest.mk @@ -17,6 +17,7 @@ Literal4 = backslash at the end^\ !UNDEF ThisIsNotDefined Literal5 = backslash at the end\# Literal6 = backslash at the end\ # errm i don't have anything to say... +Literal7 = double backslash at the end\\ SplitOverLines= \ one \ two\ diff --git a/tests/tests.cpp b/tests/tests.cpp index 0d8ee79..03541dc 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -127,6 +127,7 @@ void Tests::macros() QCOMPARE(macroTable.macroValue("Literal4"), QLatin1String("backslash at the end\\")); QCOMPARE(macroTable.macroValue("Literal5"), QLatin1String("backslash at the end\\")); QCOMPARE(macroTable.macroValue("Literal6"), QLatin1String("backslash at the end\\")); + QCOMPARE(macroTable.macroValue("Literal7"), QLatin1String("double backslash at the end\\\\")); QCOMPARE(macroTable.macroValue("SplitOverLines"), QLatin1String("one two three")); QCOMPARE(macroTable.macroValue("Incremental"), QLatin1String("one two")); QCOMPARE(macroTable.expandMacros(macroTable.macroValue("LateDefinition")), -- cgit v1.2.3