From 745189d10b84892dce9edd60be9d963dbacdc4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Gr=C3=BCnwald?= Date: Fri, 16 Feb 2024 23:02:37 +0100 Subject: [PATCH] Fix FormatException in GitLabCILog when log message contains curly braces Adjust call to IConsole.WriteLine() / IConsole.WriteErrorLine() in GitLabCILog to avoid that the log message is interpreted as format string. --- src/Cake.GitLabCI.Module/GitLabCILog.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Cake.GitLabCI.Module/GitLabCILog.cs b/src/Cake.GitLabCI.Module/GitLabCILog.cs index 32af678c..ab8769ab 100644 --- a/src/Cake.GitLabCI.Module/GitLabCILog.cs +++ b/src/Cake.GitLabCI.Module/GitLabCILog.cs @@ -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); } } }