Skip to content

Commit

Permalink
Fix bug: Exec task trims leading whitespace in ConsoleToMsBuild (#9722)
Browse files Browse the repository at this point in the history
* fix bug Exec task trims leading whitespace in ConsoleToMsBuild
  • Loading branch information
surayya-MS committed Feb 9, 2024
1 parent e71eb7a commit c6bee85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/Tasks.UnitTests/Exec_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,25 @@ public void EndToEndMultilineExec_EscapeSpecialCharacters()
}
}
}

[Fact]
public void ConsoleOutputDoesNotTrimLeadingWhitespace()
{
string lineWithLeadingWhitespace = " line with some leading whitespace";

using (var env = TestEnvironment.Create(_output))
{
var textFilePath = env.CreateFile("leading-whitespace.txt", lineWithLeadingWhitespace).Path;
Exec exec = PrepareExec(NativeMethodsShared.IsWindows ? $"type {textFilePath}" : $"cat {textFilePath}");
exec.ConsoleToMSBuild = true;

bool result = exec.Execute();

result.ShouldBeTrue();
exec.ConsoleOutput.Length.ShouldBe(1);
exec.ConsoleOutput[0].ItemSpec.ShouldBe(lineWithLeadingWhitespace);
}
}
}

internal sealed class ExecWrapper : Exec
Expand Down
5 changes: 4 additions & 1 deletion src/Tasks/Exec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport

if (ConsoleToMSBuild)
{
string trimmedTextLine = singleLine.Trim();
string trimmedTextLine = ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10) ?
singleLine.TrimEnd() :
singleLine.Trim();

if (trimmedTextLine.Length > 0)
{
// The lines read may be unescaped, so we need to escape them
Expand Down

0 comments on commit c6bee85

Please sign in to comment.