Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -253,15 +253,15 @@ internal PathInfo SetLocation(string path, CmdletProviderContext context, bool l
throw new InvalidOperationException(SessionStateStrings.LocationUndoStackIsEmpty);
}

path = _setLocationHistory.Undo(this.CurrentLocation).Path;
path = GetEscapedLocationHistoryPath(_setLocationHistory.Undo(this.CurrentLocation));
break;
case string originalPathSwitch when !literalPath && originalPathSwitch.Equals("+", StringComparison.Ordinal):
if (_setLocationHistory.RedoCount <= 0)
{
throw new InvalidOperationException(SessionStateStrings.LocationRedoStackIsEmpty);
}

path = _setLocationHistory.Redo(this.CurrentLocation).Path;
path = GetEscapedLocationHistoryPath(_setLocationHistory.Redo(this.CurrentLocation));
break;
default:
var pushPathInfo = GetNewPushPathInfo();
Expand Down Expand Up @@ -855,6 +855,13 @@ private PathInfo GetNewPushPathInfo()
return newPushLocation;
}

private static string GetEscapedLocationHistoryPath(PathInfo location)
{
return LocationGlobber.GetMshQualifiedPath(
WildcardPattern.Escape(location.Path),
location.GetDrive());
}
Comment on lines +858 to +863

/// <summary>
/// Resets the current working drive and directory to the first
/// entry on the working directory stack and removes that entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,24 @@ Describe "Set-Location" -Tags "CI" {
(Get-Location).Path | Should -Be $initialLocation
}

It 'Should go through locations with wildcard characters when specifying minus and plus as paths' {
$testPath = Join-Path $TestDrive 'foo - bar(123-456)[foo]'
$otherPath = Join-Path $TestDrive 'other'
$null = New-Item -ItemType Directory -Path $testPath
$null = New-Item -ItemType Directory -Path $otherPath

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
Comment on lines +157 to +167
}

It 'Should go back to previous locations when specifying minus twice' {
$initialLocation = (Get-Location).Path
Set-Location ([System.IO.Path]::GetTempPath())
Expand Down