Skip to content
Closed
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 @@ -501,10 +501,10 @@ private Collection<PathInfo> ResolveDriveQualifiedPath(

Collection<string> stringResult = new Collection<string>();

// if the directory exists, just return it
// If filesystem provider and the directory exists, just return it.
try
{
if (Utils.NativeDirectoryExists(userPath))
if (provider.Name.Equals(Microsoft.PowerShell.Commands.FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase) && Utils.NativeDirectoryExists(userPath))
{
result.Add(new PathInfo(drive, provider, userPath, _sessionState));
return result;
Expand Down Expand Up @@ -1750,7 +1750,9 @@ internal bool IsAbsolutePath(string path, out string driveName)
break;
}

// check if we're on a single root filesystem and it's an absolute path
// Check if we're on a single root filesystem and it's an absolute path.
// This means that even if we are in a PSDrive, on non-Windows a path starting
// with DirectorySeparatorChar will always refer to the filesystem.
if (IsSingleFileSystemAbsolutePath(path))
{
driveName = StringLiterals.DefaultPathSeparatorString;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "Set-Location" -Tags "CI" {

BeforeAll {
Expand Down Expand Up @@ -53,6 +54,22 @@ Describe "Set-Location" -Tags "CI" {
$(Get-Location).Path | Should -BeExactly $testPath.FullName
}

It "Should not use filesystem root folder if not in filesystem provider" -Skip:(!$IsWindows) {
# find filesystem root folder that doesn't exist in HKCU:
$foundFolder = $false
foreach ($folder in (Get-ChildItem "${env:SystemDrive}\" -Directory)) {
if (!(Test-Path "HKCU:\$($folder.Name)")) {
$testFolder = $folder.Name
$foundFolder = $true
break
}
}
$foundFolder | Should -BeTrue
Set-Location HKCU:\
{ Set-Location ([System.IO.Path]::DirectorySeparatorChar + $testFolder) -ErrorAction Stop } |
Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand"
}

Context 'Set-Location with no arguments' {

It 'Should go to $env:HOME when Set-Location run with no arguments from FileSystem provider' {
Expand Down