From 99e67a7a73a0d9851b46ff3770bbbf580eff4c66 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 6 Mar 2023 09:12:53 -0800 Subject: [PATCH] Fix `PlainText` output to correctly remove Reset VT sequence w/o number --- .../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 6fa725c574f..c76d5ebc50e 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/StringDecorated.cs @@ -98,7 +98,7 @@ private string PlainText } // 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 0784c7a1f29..18adcf6a8d8 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' } }