Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f20a9e4
Update DefaultSetDriveFunctionText for literal path
GameMicrowave Dec 8, 2025
18386c5
Suppress wildcard expansion for location history paths
GameMicrowave Dec 8, 2025
788cddf
Add test for Set-Location with wildcard history paths
GameMicrowave Dec 8, 2025
f48fe20
Fix wildcard path handling in Set-Location tests
GameMicrowave Dec 8, 2025
95d4d66
Merge branch 'master' into PathIssue
GameMicrowave Dec 9, 2025
831ee8e
Enhance ResolvePathCommand for literal base path handling
GameMicrowave Dec 10, 2025
da9f51c
Merge branch 'master' into PathIssue
GameMicrowave Dec 11, 2025
97aec45
Update src/Microsoft.PowerShell.Commands.Management/commands/manageme…
GameMicrowave Dec 11, 2025
e5f3a70
Make parameter `-RelativeBasePath` of Resolve-Path command
GameMicrowave Dec 11, 2025
9e30d0c
Enhance Resolve-Path tests for wildcard handling
GameMicrowave Dec 11, 2025
682737b
Add a tab completion test for -RelativeBasePath of Resolve-Path
GameMicrowave Dec 18, 2025
ad9f57e
simplify tab completion code for parameter '-RelativeBasePath' of Res…
GameMicrowave Dec 18, 2025
737426c
Merge branch 'master' into PathIssue
GameMicrowave Dec 18, 2025
2a669b5
Merge branch 'master' into PathIssue
GameMicrowave Jan 14, 2026
99f084e
Merge branch 'master' into PathIssue
GameMicrowave Jan 15, 2026
96e5d50
Merge branch 'master' into PathIssue
GameMicrowave Jan 20, 2026
ac4e049
Merge branch 'master' into PathIssue
GameMicrowave Feb 2, 2026
c3f81f1
Eliminate potential issues in the code
GameMicrowave Feb 8, 2026
0a7ffdb
Merge branch 'master' into PathIssue
GameMicrowave Feb 9, 2026
afddcb4
Merge branch 'master' into PathIssue
GameMicrowave Feb 19, 2026
fa477aa
Merge branch 'master' into PathIssue
GameMicrowave Apr 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ protected override void BeginProcessing()
{
try
{
_relativeBasePath = SessionState.Internal.Globber.GetProviderPath(RelativeBasePath, CmdletProviderContext, out _, out _relativeDrive);
// Since there is only one base path, it should be parsed literally.
_relativeBasePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(RelativeBasePath, CmdletProviderContext, out _, out _relativeDrive);
}
catch (ProviderNotFoundException providerNotFound)
{
Expand Down Expand Up @@ -190,8 +191,16 @@ protected override void ProcessRecord()
try
{
SessionState.Path.PushCurrentLocation(string.Empty);
_ = SessionState.Path.SetLocation(_relativeBasePath);
result = SessionState.Path.GetResolvedPSPathFromPSPath(path, CmdletProviderContext);
var cmdpvdContext = CmdletProviderContext;

// Specify that the base path should be treated literally.
cmdpvdContext.SuppressWildcardExpansion = true;

// A potential bug is that using the `SetLocation` method modifies the history stack,
// which can unexpectedly affect the results of commands that rely on the history stack, such as `Set-Location +`.
_ = SessionState.Path.SetLocation(_relativeBasePath, cmdpvdContext, true);
cmdpvdContext.SuppressWildcardExpansion = SuppressWildcardExpansion;
result = SessionState.Path.GetResolvedPSPathFromPSPath(path, cmdpvdContext);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2462,6 +2462,11 @@ private static void NativeCommandArgumentCompletion(
NativeCompletionSetLocationCommand(context, parameterName, result);
break;
}
case "Resolve-Path" when parameterName.Equals("RelativeBasePath", StringComparison.OrdinalIgnoreCase):
{
NativeCompletionPathArgument(context, "LiteralPath", result);
break;
}
case "Move-Item":
case "Copy-Item":
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4889,7 +4889,7 @@ internal static SessionStateAliasEntry[] BuiltInAliases
# .ExternalHelp System.Management.Automation.dll-help.xml
";

internal const string DefaultSetDriveFunctionText = "Set-Location $MyInvocation.MyCommand.Name";
internal const string DefaultSetDriveFunctionText = "Set-Location -LiteralPath $MyInvocation.MyCommand.Name";

internal static readonly ScriptBlock SetDriveScriptBlock = ScriptBlock.CreateDelayParsedScriptBlock(DefaultSetDriveFunctionText, isProductCode: true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ internal PathInfo SetLocation(string path, CmdletProviderContext context, bool l
throw new InvalidOperationException(SessionStateStrings.LocationUndoStackIsEmpty);
}

// Should process history path as literal
context ??= new CmdletProviderContext(this.ExecutionContext);
context.SuppressWildcardExpansion = true;
path = _setLocationHistory.Undo(this.CurrentLocation).Path;
break;
case string originalPathSwitch when !literalPath && originalPathSwitch.Equals("+", StringComparison.Ordinal):
Expand All @@ -261,6 +264,9 @@ internal PathInfo SetLocation(string path, CmdletProviderContext context, bool l
throw new InvalidOperationException(SessionStateStrings.LocationRedoStackIsEmpty);
}

// Should process history path as literal
context ??= new CmdletProviderContext(this.ExecutionContext);
context.SuppressWildcardExpansion = true;
path = _setLocationHistory.Redo(this.CurrentLocation).Path;
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,31 @@ Describe "Resolve-Path returns proper path" -Tag "CI" {
(Resolve-Path -Path $Path -RelativeBasePath $BasePath -Force:$Force).Path | Should -BeExactly $ExpectedResult
}
}


Describe "The parameter '-RelativeBasePath' should treat path as literal" -Tags "CI" {
BeforeAll {
$testFolder = 'TestDrive:\[Folder]'
New-Item -ItemType Directory -Path $testFolder
Push-Location -LiteralPath $testFolder
}

It "Should succeed in resolving a path when the relative base path contains a wildcard character" {
Resolve-Path -LiteralPath . -RelativeBasePath . | Should -BeTrue
Resolve-Path -LiteralPath . -RelativeBasePath . -Relative | Should -BeTrue
Resolve-Path -Path . -RelativeBasePath . | Should -BeTrue
Resolve-Path -Path . -RelativeBasePath . -Relative | Should -BeTrue
}

It "Should fill path with literal in tab completion of parameter '-RelativeBasePath'" {
$wildcardNameFile = '[WildcardName].txt'
123 | Out-File -LiteralPath $wildcardNameFile
$completionInfo = TabExpansion2 'Resolve-Path -RelativeBasePath .\'
$completionInfo.CompletionMatches[0].ListItemText | Should -Be $wildcardNameFile
}

AfterAll {
Pop-Location
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@ Describe "Set-Location" -Tags "CI" {
(Get-Location).Path | Should -Be $tempPath
{ Set-Location + } | Should -Throw -ErrorId 'System.InvalidOperationException,Microsoft.PowerShell.Commands.SetLocationCommand'
}

It 'Should go to last location back, even if any path contains wildcard' {
$initialLocation = (Get-Location).Path
$wildcardPath = 'TestDrive:\[Folder]'
# Use the return path of `New-Item` to avoid incorrect results caused by the different slash directions of path separators on different operating systems.
$wildcardLocation = (New-Item $wildcardPath -Type Directory).FullName

Set-Location -LiteralPath $wildcardLocation
Set-Location -
(Get-Location).Path | Should -Be $initialLocation
Set-Location +
(Get-Location).Path | Should -Be $wildcardLocation

Set-Location -LiteralPath $initialLocation
Set-Location -
(Get-Location).Path | Should -Be $wildcardLocation
Set-Location +
(Get-Location).Path | Should -Be $initialLocation
}
}

It 'Should nativate to literal path "<path>"' -TestCases @(
Expand Down Expand Up @@ -249,7 +268,7 @@ Describe "Set-Location" -Tags "CI" {
#root is / on linux and Mac, so it's not happy with this check.
Set-Location 'TestDrive:\'
$DriveRoot = (Get-Location).path
New-Item -Path 'TestDrive:\Directory1' -Name 'Directory2' -ItemType Directory
New-Item -Path 'TestDrive:\Directory1' -Name 'Directory2' -ItemType Directory -ErrorAction Ignore
Set-Location 'TestDrive:\Directory1\Directory2'
cd\
(Get-Location).Path | Should -BeExactly $DriveRoot
Expand Down