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