Skip to content

Conversation

@GameMicrowave
Copy link
Contributor

@GameMicrowave GameMicrowave commented Dec 8, 2025

PR Summary

Fix #25282
Fix #20701
Fix #20931

Literal processing actual path to avoid misinterpreting wildcards

PR Context

Incorrectly interpreting wildcards in the history path

If you have two file drives, and you first enter a folder with a path containing “pwsh wildcards” (mainly square brackets), then switch to another drive and switch back, pwsh will incorrectly interpret the wildcards in the path, resulting in an error.

For example, if you are currently in a folder with the path C:\pwsh[net10], and then you type D: and press Enter, followed by typing C: and pressing Enter, you will be able to observe this error.

Using Set-Location + or Set-Location - to navigate through history has the same issue: if any previous path contains PowerShell wildcards, an error occurs when trying to switch to it.

Incorrectly interpreting wildcards in the relative path twice in succession

the Resolve-Path command behaves similarly when handling paths. The specific reason is that Resolve-Path resolves wildcards twice for the path passed via -RelativeBasePath and then navigates to the resulting location. If the path itself contains wildcards, it cannot be resolved correctly.

PR Checklist

Literal processing path to avoid misinterpreting wildcards
@iSazonov
Copy link
Collaborator

iSazonov commented Dec 8, 2025

From previous investigations it is not full fix.

@GameMicrowave GameMicrowave marked this pull request as draft December 8, 2025 05:17
Added suppression of wildcard expansion for history paths.
Avoid incorrect results caused by the different slash directions of path separators on different operating systems.
@GameMicrowave GameMicrowave changed the title Update DefaultSetDriveFunctionText for literal path Ensure history path handling as literal Dec 8, 2025
Updated the ResolvePathCommand to treat the base path literally and suppress wildcard expansion during path resolution.
Copy link
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

This pull request fixes issues #25282 and #20701 where PowerShell incorrectly interprets wildcard characters (particularly square brackets) in file paths when using Set-Location with history navigation (Set-Location - or Set-Location +) or when switching between drives using drive letter shortcuts (e.g., C:, D:).

Key Changes

  • Modified SessionStateLocationAPIs.cs to suppress wildcard expansion when retrieving paths from location history
  • Updated InitialSessionState.cs to use -LiteralPath parameter in the default drive-switching function
  • Enhanced ResolvePathCommand.cs to handle the RelativeBasePath parameter as a literal path
  • Added comprehensive test coverage for wildcard paths in location history

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/System.Management.Automation/engine/SessionStateLocationAPIs.cs Adds context.SuppressWildcardExpansion = true before Undo/Redo operations to treat history paths as literals
src/System.Management.Automation/engine/InitialSessionState.cs Changes default drive function to use -LiteralPath parameter instead of the positional Path parameter
src/Microsoft.PowerShell.Commands.Management/commands/management/ResolvePathCommand.cs Updates RelativeBasePath handling to process it as a literal path and sets wildcard suppression when changing location
test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 Adds new test case for wildcard paths in history navigation and adds -ErrorAction Ignore for consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

GameMicrowave and others added 2 commits December 11, 2025 21:57
…nt/ResolvePathCommand.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@GameMicrowave GameMicrowave changed the title Ensure history path handling as literal Ensure that actually existing paths are processed literally Dec 11, 2025
@GameMicrowave GameMicrowave marked this pull request as ready for review December 11, 2025 16:56
@GameMicrowave GameMicrowave marked this pull request as draft December 11, 2025 16:58
Add tests for Resolve-Path with wildcard characters in RelativeBasePath
@GameMicrowave GameMicrowave marked this pull request as ready for review December 11, 2025 17:26
@iSazonov iSazonov requested a review from Copilot December 11, 2025 18:08
Copy link
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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GameMicrowave GameMicrowave marked this pull request as draft December 18, 2025 04:56
@GameMicrowave GameMicrowave marked this pull request as ready for review December 19, 2025 17:18
@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Dec 26, 2025
@microsoft-github-policy-service
Copy link
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review - Needed The PR is being reviewed

Projects

None yet

2 participants