From 099a0d3eac33790998b742ad32f7adda46c00dbf Mon Sep 17 00:00:00 2001 From: 26zl <143036376+26zl@users.noreply.github.com> Date: Sat, 26 Sep 2026 14:45:25 +0200 Subject: [PATCH] Uninstall: remove the previous release's Oh My Posh block and validate the profile only in pwsh Remove-DevConfigOhMyPoshProfile compared the profile text as read, but the block the previous signed release wrote has mixed line endings: CRLF inside the here-string (the release file is CRLF) and LF after it. Neither the LF nor the CRLF candidate matched, so nothing was removed and the untouched profile was re-parsed by the cleanup host, Windows PowerShell, which rejects the block's leading pipe; the step was flagged with "An empty pipe element is not allowed". Setup already normalizes line endings before comparing; cleanup now does the same. The post-removal parse also failed for any PowerShell 7 syntax elsewhere in the pwsh profile (for example ??), because the cleanup always runs in Windows PowerShell. Only pwsh can validate its own profile, so the check is skipped under the Desktop edition; removal is an exact match at a top-level statement start either way. --- src/windows-dev-config/steps/powershell-profile.ps1 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/windows-dev-config/steps/powershell-profile.ps1 b/src/windows-dev-config/steps/powershell-profile.ps1 index 42b34d9..e7567ba 100644 --- a/src/windows-dev-config/steps/powershell-profile.ps1 +++ b/src/windows-dev-config/steps/powershell-profile.ps1 @@ -121,7 +121,8 @@ function Remove-DevConfigOhMyPoshProfile { if (-not $profilePath) { $profilePath = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'PowerShell\Microsoft.PowerShell_profile.ps1' } - $original = [string](Read-DevConfigTextFile -Path $profilePath) + # The previous release wrote the block with mixed line endings, so compare normalized text, as setup does. + $original = [string](Read-DevConfigTextFile -Path $profilePath) -replace "`r`n", "`n" $tokens = $null $parseErrors = $null $ast = [System.Management.Automation.Language.Parser]::ParseInput($original, [ref]$tokens, [ref]$parseErrors) @@ -130,7 +131,6 @@ function Remove-DevConfigOhMyPoshProfile { Get-DevConfigOhMyPoshProfileBlock "$Script:OhMyPoshInitCommand`n | Invoke-Expression`n" -replace "`r`n", "`n" ) - $blocks += @($blocks | ForEach-Object { $_.Replace("`n", "`r`n") }) if ($ast.EndBlock) { # Match only top-level setup blocks, not examples in strings or custom functions. foreach ($statement in @($ast.EndBlock.Statements | Sort-Object { $_.Extent.StartOffset } -Descending)) { @@ -143,8 +143,11 @@ function Remove-DevConfigOhMyPoshProfile { } } } - # Validate after removing setup blocks, whose leading-pipe syntax requires PowerShell 7. - [void](Get-DevConfigProfileAst -Content $content) + # Only PowerShell 7 can validate its own profile: the block's leading pipe, and anything else pwsh accepts, + # are parse errors in Windows PowerShell, which runs the cleanup. Removal is an exact match at a statement start. + if ($PSVersionTable.PSEdition -ne 'Desktop') { + [void](Get-DevConfigProfileAst -Content $content) + } if ($CheckOnly) { return $content -eq $original }