mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user