Skip to content

Commit 66a8982

Browse files
authored
Fix PlainText output to correctly remove Reset VT sequence w/o number (PowerShell#19283)
1 parent ff32e01 commit 66a8982

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private string PlainText
9898
}
9999

100100
// graphics/color mode ESC[1;2;...m
101-
private const string GraphicsRegex = @"(\x1b\[\d+(;\d+)*m)";
101+
private const string GraphicsRegex = @"(\x1b\[\d*(;\d+)*m)";
102102

103103
// CSI escape sequences
104104
private const string CsiRegex = @"(\x1b\[\?\d+[hl])";

test/powershell/engine/Formatting/OutputRendering.Tests.ps1

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ Describe 'OutputRendering tests' -Tag 'CI' {
8181
}
8282

8383
It 'ToString(OutputRendering) works correctly' {
84-
$s = [System.Management.Automation.Internal.StringDecorated]::new($PSStyle.Foreground.Red + 'Hello')
84+
$s = [System.Management.Automation.Internal.StringDecorated]::new($PSStyle.Foreground.Red + "Hello`e[m.")
8585
$s.IsDecorated | Should -BeTrue
86-
$s.ToString() | Should -BeExactly "$($PSStyle.Foreground.Red)Hello"
87-
$s.ToString([System.Management.Automation.OutputRendering]::ANSI) | Should -BeExactly "$($PSStyle.Foreground.Red)Hello"
88-
$s.ToString([System.Management.Automation.OutputRendering]::PlainText) | Should -BeExactly 'Hello'
86+
$s.ToString() | Should -BeExactly "$($PSStyle.Foreground.Red)Hello`e[m."
87+
$s.ToString([System.Management.Automation.OutputRendering]::ANSI) | Should -BeExactly "$($PSStyle.Foreground.Red)Hello`e[m."
88+
$s.ToString([System.Management.Automation.OutputRendering]::PlainText) | Should -BeExactly 'Hello.'
8989
{ $s.ToString([System.Management.Automation.OutputRendering]::Host) } | Should -Throw -ErrorId 'ArgumentException'
9090
}
9191
}

0 commit comments

Comments
 (0)