From 66a89826bbaa7bb35c2938c3afc7785c469dbaba Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 7 Mar 2023 14:18:16 -0800 Subject: [PATCH] Fix `PlainText` output to correctly remove Reset VT sequence w/o number (#19283) --- .../FormatAndOutput/common/StringDecorated.cs | 2 +- .../engine/Formatting/OutputRendering.Tests.ps1 | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs b/src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs index 6fa725c574..c76d5ebc50 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs @@ -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])"; diff --git a/test/powershell/engine/Formatting/OutputRendering.Tests.ps1 b/test/powershell/engine/Formatting/OutputRendering.Tests.ps1 index 0784c7a1f2..18adcf6a8d 100644 --- a/test/powershell/engine/Formatting/OutputRendering.Tests.ps1 +++ b/test/powershell/engine/Formatting/OutputRendering.Tests.ps1 @@ -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' } }