Skip to content

Commit

Permalink
Fix color code detection in OutputManager
Browse files Browse the repository at this point in the history
This was a simple case of a mistaken translation from shell escape cades
(which support "\nnn") to C# (which only supports "\xNN" and "\uNNNN").
The test was passing because it also used invalid escape codes.
  • Loading branch information
ian-h-chamberlain committed Feb 12, 2023
1 parent 97195ba commit 071a612
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Runner.Worker/Handlers/OutputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace GitHub.Runner.Worker.Handlers
{
public sealed class OutputManager : IDisposable
{
private const string _colorCodePrefix = "\033[";
private const string _colorCodePrefix = "\x1b[";
private const int _maxAttempts = 3;
private const string _timeoutKey = "GITHUB_ACTIONS_RUNNER_ISSUE_MATCHER_TIMEOUT";
private static readonly Regex _colorCodeRegex = new(@"\x0033\[[0-9;]*m?", RegexOptions.Compiled | RegexOptions.CultureInvariant);
private static readonly Regex _colorCodeRegex = new(@"\x1b\[[0-9;]*m?", RegexOptions.Compiled | RegexOptions.CultureInvariant);
private readonly IActionCommandManager _commandManager;
private readonly ContainerInfo _container;
private readonly IExecutionContext _executionContext;
Expand Down
3 changes: 2 additions & 1 deletion src/Test/L0/Worker/OutputManagerL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ public void MatcherRemoveColorCodes()
},
},
});
Process("the error: \033[31mred, \033[1;31mbright red, \033[mreset");
// Shells may support "\033", but in C# that translates to a null followed by "33"
Process("the error: \x1B[31mred, \x1B[1;31mbright red, \x1B[mreset");
Assert.Equal(1, _issues.Count);
Assert.Equal("red, bright red, reset", _issues[0].Item1.Message);
Assert.Equal("the error: red, bright red, reset", _issues[0].Item2);
Expand Down

0 comments on commit 071a612

Please sign in to comment.