From cb2a241e02d8ef8e878959c07490703c02d82007 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 30 Nov 2020 15:11:30 +0100 Subject: [PATCH] Utils: Filter adjacent carriage returns in OutputFormatter It shouldn't change the semantics, and it helps on some systems with strange line endings. Fixes: QTCREATORBUG-24556 Change-Id: I8158ddda458e5500bce6ce7b9ff4d5d981f88d7d Reviewed-by: Alessandro Portale --- src/libs/utils/synchronousprocess.cpp | 7 ++++++- src/plugins/coreplugin/outputwindow.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/synchronousprocess.cpp b/src/libs/utils/synchronousprocess.cpp index 16e911eb8a1..81a29d14d2a 100644 --- a/src/libs/utils/synchronousprocess.cpp +++ b/src/libs/utils/synchronousprocess.cpp @@ -39,6 +39,7 @@ #include +#include #include #include @@ -803,7 +804,11 @@ QString SynchronousProcess::locateBinary(const QString &path, const QString &bin QString SynchronousProcess::normalizeNewlines(const QString &text) { QString res = text; - res.replace(QLatin1String("\r\n"), QLatin1String("\n")); + const auto newEnd = std::unique(res.begin(), res.end(), [](const QChar &c1, const QChar &c2) { + return c1 == '\r' && c2 == '\r'; // QTCREATORBUG-24556 + }); + res.chop(std::distance(newEnd, res.end())); + res.replace("\r\n", "\n"); return res; } diff --git a/src/plugins/coreplugin/outputwindow.cpp b/src/plugins/coreplugin/outputwindow.cpp index 8766305885e..ae0cb36c003 100644 --- a/src/plugins/coreplugin/outputwindow.cpp +++ b/src/plugins/coreplugin/outputwindow.cpp @@ -627,7 +627,7 @@ private: void Internal::CorePlugin::testOutputFormatter() { const QString input = - "B to be handled by B\r\n" + "B to be handled by B\r\r\n" "not to be handled\n\n\n\n" "A to be handled by A\n" "continuation for A\r\n"