Fix PlainText output to correctly remove Reset VT sequence w/o number (#19283)

This commit is contained in:
Steve Lee
2023-03-07 14:18:16 -08:00
committed by GitHub
parent ff32e01d31
commit 66a89826bb
2 changed files with 5 additions and 5 deletions
@@ -98,7 +98,7 @@ namespace System.Management.Automation.Internal
}
// graphics/color mode ESC[1;2;...m
private const string GraphicsRegex = @"(\x1b\[\d+(;\d+)*m)";
private const string GraphicsRegex = @"(\x1b\[\d*(;\d+)*m)";
// CSI escape sequences
private const string CsiRegex = @"(\x1b\[\?\d+[hl])";
@@ -81,11 +81,11 @@ Describe 'OutputRendering tests' -Tag 'CI' {
}
It 'ToString(OutputRendering) works correctly' {
$s = [System.Management.Automation.Internal.StringDecorated]::new($PSStyle.Foreground.Red + 'Hello')
$s = [System.Management.Automation.Internal.StringDecorated]::new($PSStyle.Foreground.Red + "Hello`e[m.")
$s.IsDecorated | Should -BeTrue
$s.ToString() | Should -BeExactly "$($PSStyle.Foreground.Red)Hello"
$s.ToString([System.Management.Automation.OutputRendering]::ANSI) | Should -BeExactly "$($PSStyle.Foreground.Red)Hello"
$s.ToString([System.Management.Automation.OutputRendering]::PlainText) | Should -BeExactly 'Hello'
$s.ToString() | Should -BeExactly "$($PSStyle.Foreground.Red)Hello`e[m."
$s.ToString([System.Management.Automation.OutputRendering]::ANSI) | Should -BeExactly "$($PSStyle.Foreground.Red)Hello`e[m."
$s.ToString([System.Management.Automation.OutputRendering]::PlainText) | Should -BeExactly 'Hello.'
{ $s.ToString([System.Management.Automation.OutputRendering]::Host) } | Should -Throw -ErrorId 'ArgumentException'
}
}