diff --git a/src/libcalamares/utils/String.cpp b/src/libcalamares/utils/String.cpp index 570e2800d..0c7bf8fb5 100644 --- a/src/libcalamares/utils/String.cpp +++ b/src/libcalamares/utils/String.cpp @@ -135,7 +135,8 @@ truncateMultiLine( const QString& string, CalamaresUtils::LinesStartEnd lines, C return shorter; } - if ( ( string.length() <= chars.total ) && ( string.count( NEWLINE ) <= maxLines ) ) + const int linesInString = string.count( NEWLINE ) + ( string.endsWith( NEWLINE ) ? 0 : 1 ); + if ( ( string.length() <= chars.total ) && ( linesInString <= maxLines ) ) { return string; } diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index 539113d91..3992fe78a 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -600,13 +600,37 @@ and the translations updated.)" ); // Grab first line, untruncated { - auto s = truncateMultiLine( longString, LinesStartEnd { 1, 0 } ); QVERIFY( s.length() > 1 ); QVERIFY( longString.startsWith( s ) ); QVERIFY( s.endsWith( NEWLINE ) ); QVERIFY( s.endsWith( "being\n" ) ); + QVERIFY( s.startsWith( "Some " ) ); } + + // Grab last line, untruncated + { + auto s = truncateMultiLine( longString, LinesStartEnd { 0, 1 } ); + QVERIFY( s.length() > 1 ); + QVERIFY( longString.endsWith( s ) ); + QVERIFY( !s.endsWith( NEWLINE ) ); + QVERIFY( s.endsWith( "updated." ) ); + QCOMPARE( s.count( NEWLINE ), 0 ); // Because last line doesn't end with a newline + QVERIFY( s.startsWith( "and the " ) ); + } + + // Grab last two lines, untruncated + { + auto s = truncateMultiLine( longString, LinesStartEnd { 0, 2 } ); + QVERIFY( s.length() > 1 ); + QVERIFY( longString.endsWith( s ) ); + QVERIFY( !s.endsWith( NEWLINE ) ); + QVERIFY( s.endsWith( "updated." ) ); + cDebug() << "Result-line" << Logger::Quote << s; + QCOMPARE( s.count( NEWLINE ), 1 ); // Because last line doesn't end with a newline + QVERIFY( s.startsWith( "displayed in " ) ); + } + }