Skip to content

Treat Set-Location history paths as literal#27521

Open
KirtiRamchandani wants to merge 1 commit into
PowerShell:masterfrom
KirtiRamchandani:fix/set-location-history-literal
Open

Treat Set-Location history paths as literal#27521
KirtiRamchandani wants to merge 1 commit into
PowerShell:masterfrom
KirtiRamchandani:fix/set-location-history-literal

Conversation

@KirtiRamchandani
Copy link
Copy Markdown

Summary

  • Treat Set-Location - / Set-Location + history entries as literal paths after they are read from location history
  • Add regression coverage for history navigation to a directory whose name contains wildcard characters

Details

PathInfo.Path values stored in the Set-Location history are already resolved paths. When - or + replaced the user input with a history path, the path was still globbed as a normal -Path value, so folder names containing characters like [ and ] failed to resolve.

Fixes #20701
Related #27507

Validation

  • Start-PSBuild -NoPSModuleRestore -CI -SkipExperimentalFeatureGeneration -UseNuGetOrg reached publish and produced pwsh.exe; the Windows PowerShell-hosted local run failed afterward in post-publish cleanup (Clear-NativeDependencies parameter binding).
  • Start-PSPester -Path ./test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 -powershell ./src/powershell-win-core/bin/Debug/net11.0/win7-x64/publish/pwsh.exe -UseNuGetOrg -SkipTestToolBuild -ThrowOnFailure passed: 22 passed, 0 failed, 2 skipped, 1 pending.

Copilot AI review requested due to automatic review settings May 24, 2026 18:39
@KirtiRamchandani KirtiRamchandani requested a review from a team as a code owner May 24, 2026 18:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds coverage and implementation changes so Set-Location -/+ history navigation treats stored paths literally (no wildcard expansion), matching -LiteralPath behavior for history entries that contain wildcard-special characters.

Changes:

  • Added a Pester test validating history navigation with wildcard-special characters in the path.
  • Updated SessionStateLocationAPIs.SetLocation to suppress wildcard expansion when navigating location history (- / +) and for -LiteralPath.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 Adds regression test for history navigation with wildcard-special characters in paths.
src/System.Management.Automation/engine/SessionStateLocationAPIs.cs Suppresses wildcard expansion when applying history undo/redo paths (and when -LiteralPath is used).

Comment on lines +324 to +327
if (suppressWildcardExpansion)
{
context.SuppressWildcardExpansion = true;
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in d1f8a3918: context.SuppressWildcardExpansion now preserves an existing true value with |= suppressWildcardExpansion.

@KirtiRamchandani KirtiRamchandani force-pushed the fix/set-location-history-literal branch from a5d3dd3 to d1f8a39 Compare May 24, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set-Location -Path + fails because it mishandles the history (version 7.4.0)

2 participants