From 2db8516a8c71ff023242a77e4162c5270ac73e7f Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 26 Feb 2020 08:07:57 -0800 Subject: [PATCH] Fix ConciseView to not show the line information within the error messages (#11952) --- .../DefaultFormatters/PowerShellCore_format_ps1xml.cs | 3 ++- test/powershell/engine/Formatting/ErrorView.Tests.ps1 | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index 09cc323b93..e7003f4758 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -1100,7 +1100,8 @@ namespace System.Management.Automation.Runspaces $offsetInLine = 0 } else { - $positionMessage = $myinv.PositionMessage.Split($newline) + # use newline char instead of $newline because that is what is in the message + $positionMessage = $myinv.PositionMessage.Split(""`n"") $line = $positionMessage[1].Substring(1) # skip the '+' at the start $highlightLine = $positionMessage[$positionMessage.Count - 1].Substring(1) $offsetLength = $highlightLine.Trim().Length diff --git a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 index 112d45fc17..29b7ee98d5 100644 --- a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 +++ b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 @@ -99,6 +99,12 @@ Describe 'Tests for $ErrorView' -Tag CI { $e = { throw "$msg" } | Should -Throw $msg -PassThru | Out-String $e | Should -BeLike "*$msg*" } + + It "Position message does not contain line information" { + + $e = & "$PSHOME/pwsh" -noprofile -command "foreach abc" | Out-String + $e | Should -Not -BeLike "*At line*" + } } Context 'NormalView tests' {