From 071a612dfe86c856dd1f6ac4291392ce1b6a73bc Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sun, 12 Feb 2023 14:41:45 -0500 Subject: [PATCH] Fix color code detection in OutputManager 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. --- src/Runner.Worker/Handlers/OutputManager.cs | 4 ++-- src/Test/L0/Worker/OutputManagerL0.cs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Runner.Worker/Handlers/OutputManager.cs b/src/Runner.Worker/Handlers/OutputManager.cs index 8b97c867d95..4c9d5f4f405 100644 --- a/src/Runner.Worker/Handlers/OutputManager.cs +++ b/src/Runner.Worker/Handlers/OutputManager.cs @@ -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; diff --git a/src/Test/L0/Worker/OutputManagerL0.cs b/src/Test/L0/Worker/OutputManagerL0.cs index 8bac9393362..920ccdd175c 100644 --- a/src/Test/L0/Worker/OutputManagerL0.cs +++ b/src/Test/L0/Worker/OutputManagerL0.cs @@ -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);