Skip to content

Commit

Permalink
Fix FormatException in GitLabCILog when log message contains curly br…
Browse files Browse the repository at this point in the history
…aces

Adjust call to IConsole.WriteLine() / IConsole.WriteErrorLine() in GitLabCILog to avoid that the log message is interpreted as format string.
  • Loading branch information
ap0llo authored and nils-a committed Feb 16, 2024
1 parent 74cee1f commit 745189d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Cake.GitLabCI.Module/GitLabCILog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ public void Write(Verbosity verbosity, LogLevel level, string format, params obj
message = $"{level}: {string.Format(format, args)}";
}

// Passing a string to IConsole.WriteLine() / IConsole.WriteErrorLine() will cause that string to be interpreted as format string.
// This will cause an error if the string contains curly braces and WriteLine() will faile with a FormatException.
// To avoid this, pass in the "no-op" format string and pass the text to write to the console as argument that will be formatted into the format string
if (level > LogLevel.Error)
{
_console.WriteLine(message);
_console.WriteLine("{0}", message);
}
else
{
_console.WriteErrorLine(message);
_console.WriteErrorLine("{0}", message);
}
}
}
Expand Down

0 comments on commit 745189d

Please sign in to comment.