Fix Set-Location history with wildcard paths#27527
Open
KirtiRamchandani wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes Set-Location - / Set-Location + history navigation when prior locations contain wildcard characters by escaping history paths, and adds regression coverage for paths containing [ / ].
Changes:
- Escape location history paths during undo/redo (
-/+) so wildcard characters aren’t treated as glob patterns. - Add a Pester test that navigates back/forward through history when a prior path includes wildcard characters.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 | Adds regression test covering history navigation with wildcard characters in directory names. |
| src/System.Management.Automation/engine/SessionStateLocationAPIs.cs | Escapes undo/redo history paths (and re-qualifies them) before passing them back into SetLocation. |
Comment on lines
+858
to
+863
| private static string GetEscapedLocationHistoryPath(PathInfo location) | ||
| { | ||
| return LocationGlobber.GetMshQualifiedPath( | ||
| WildcardPattern.Escape(location.Path), | ||
| location.GetDrive()); | ||
| } |
Comment on lines
+157
to
+167
|
|
||
| Set-Location $TestDrive | ||
| $testDrivePath = (Get-Location).Path | ||
| Set-Location -LiteralPath $testPath | ||
| Set-Location -LiteralPath $otherPath | ||
| Set-Location - | ||
| (Get-Location).Path | Should -BeExactly $testPath | ||
| Set-Location - | ||
| (Get-Location).Path | Should -BeExactly $testDrivePath | ||
| Set-Location + | ||
| (Get-Location).Path | Should -BeExactly $testPath |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Fixes #27507.
Set-Location -andSet-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-Locationbehavior for stacked locations.PR Context
Pop-Locationalready escapes savedPathInfoentries before passing them back throughSetLocation. 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
PathNotFoundforSet-Location -Path '-'when the previous path contained[abc].Start-PSBuild -Configuration Debug -SMAOnlypwsh.exereturned 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-fatalNew-Itemmessage was printed after the passing summary).