Skip to content

Commit a285922

Browse files
authored
Merge pull request #189 from ap0llo/fix-formatexception-when-log-message-contains-brackets
Fix FormatException in GitLabCILog when log message contains curly braces
2 parents 74cee1f + 745189d commit a285922

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Cake.GitLabCI.Module/GitLabCILog.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@ public void Write(Verbosity verbosity, LogLevel level, string format, params obj
7070
message = $"{level}: {string.Format(format, args)}";
7171
}
7272

73+
// Passing a string to IConsole.WriteLine() / IConsole.WriteErrorLine() will cause that string to be interpreted as format string.
74+
// This will cause an error if the string contains curly braces and WriteLine() will faile with a FormatException.
75+
// 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
7376
if (level > LogLevel.Error)
7477
{
75-
_console.WriteLine(message);
78+
_console.WriteLine("{0}", message);
7679
}
7780
else
7881
{
79-
_console.WriteErrorLine(message);
82+
_console.WriteErrorLine("{0}", message);
8083
}
8184
}
8285
}

0 commit comments

Comments
 (0)