Update regex used to remove ANSI escape sequences to be more specific to decoration and hyperlinks (#16811)

* Update regex used to remove ANSI escape sequences to be more specific to decoration and hyperlinks

* add CSI sequence and change default back to `host`

* fix test for default outputrendering
fix regex for CSI by escaping the question mark

* remove hyperlink support
This commit is contained in:
Steve Lee
2022-03-24 17:44:35 -07:00
committed by GitHub
parent c904d7f376
commit 72e3d719d8
3 changed files with 9 additions and 3 deletions
@@ -572,7 +572,7 @@ namespace System.Management.Automation
/// <summary>
/// Gets or sets the rendering mode for output.
/// </summary>
public OutputRendering OutputRendering { get; set; } = OutputRendering.Ansi;
public OutputRendering OutputRendering { get; set; } = OutputRendering.Host;
/// <summary>
/// Gets value to turn off all attributes.
@@ -101,8 +101,14 @@ namespace System.Management.Automation.Internal
}
}
// graphics/color mode ESC[1;2;...m
private const string GraphicsRegex = @"(\x1b\[\d+(;\d+)*m)";
// CSI escape sequences
private const string CsiRegex = @"(\x1b\[\?\d+[hl])";
// replace regex with .NET 6 API once available
internal static readonly Regex AnsiRegex = new Regex(@"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])", RegexOptions.Compiled);
internal static readonly Regex AnsiRegex = new Regex($"{GraphicsRegex}|{CsiRegex}", RegexOptions.Compiled);
/// <summary>
/// Initializes a new instance of the <see cref="ValueStringDecorated"/> struct.
@@ -83,7 +83,7 @@ Describe 'Tests for $PSStyle automatic variable' {
It '$PSStyle has correct default for OutputRendering' {
$PSStyle | Should -Not -BeNullOrEmpty
$PSStyle.OutputRendering | Should -BeExactly 'Ansi'
$PSStyle.OutputRendering | Should -BeExactly 'Host'
}
It '$PSStyle has correct defaults for style <key>' -TestCases (Get-TestCases $styleDefaults) {