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' } }