◐ Shell
clean mode source ↗

Fix Set-Location history with wildcard paths by KirtiRamchandani · Pull Request #27527 · PowerShell/PowerShell

PR Summary

Fixes #27507.

Set-Location - and Set-Location + replay paths saved in the location history. When the saved path contains wildcard characters such as [foo], the replayed path was passed through normal wildcard expansion and failed to resolve the literal directory.

This change escapes the saved history path before resolving it, matching the existing Pop-Location behavior for stacked locations.

PR Context

Pop-Location already escapes saved PathInfo entries before passing them back through SetLocation. The location-history undo/redo path used the raw saved path instead, so literal filesystem names containing wildcard characters were treated as patterns.

PR Checklist

  • Tests pass

Tests

  • Manual repro before fix: old binary returned PathNotFound for Set-Location -Path '-' when the previous path contained [abc].
  • Start-PSBuild -Configuration Debug -SMAOnly
  • Manual repro after fix: publish pwsh.exe returned the wildcard-containing path successfully.
  • Start-PSPester -Path .\test\powershell\Modules\Microsoft.PowerShell.Management\Set-Location.Tests.ps1 -Terse -ThrowOnFailure (22 passed, 0 failed, 2 skipped, 1 pending; an existing non-fatal New-Item message was printed after the passing summary).