Skip to content
Merged
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
14 changes: 14 additions & 0 deletions src/System.Management.Automation/namespaces/LocationGlobber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,20 @@ private Collection<PathInfo> ResolveDriveQualifiedPath(

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

// if the directory exists, just return it
try
{
if (Utils.NativeDirectoryExists(userPath))
{
result.Add(new PathInfo(drive, provider, userPath, _sessionState));
return result;
}
}
catch
{
// in cases of Access Denied or other errors, fallback to previous behavior and let provider handle it
}

if (!context.SuppressWildcardExpansion)
{
// See if the provider will expand the wildcard
Expand Down
23 changes: 23 additions & 0 deletions test/powershell/Host/Base-Directory.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,26 @@ Describe "Configuration file locations" -tags "CI","Slow" {
}
}
}

Describe "Working directory on startup" -Tag "CI" {
BeforeAll {
$powershell = Join-Path -Path $PSHOME -ChildPath "pwsh"
$testPath = New-Item -ItemType Directory -Path "$TestDrive\test[dir]"
$currentDirectory = Get-Location
}

AfterAll {
Set-Location $currentDirectory
}

It "Can start in directory where name contains wildcard characters" {
Set-Location -LiteralPath $testPath.FullName
if ($IsMacOS) {
# on macOS, /tmp is a symlink to /private so the real path is under /private/tmp
$expectedPath = "/private" + $testPath.FullName
} else {
$expectedPath = $testPath.FullName
}
& $powershell -noprofile -c { $PWD.Path } | Should BeExactly $expectedPath
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ Describe "Set-Location" -Tags "CI" {
$result | Should BeOfType System.Management.Automation.PathInfo
}

It "Should accept path containing wildcard characters" {
$null = New-Item -ItemType Directory -Path "$TestDrive\aa"
$null = New-Item -ItemType Directory -Path "$TestDrive\ba"
$testPath = New-Item -ItemType Directory -Path "$TestDrive\[ab]a"

Set-Location $TestDrive
Set-Location -Path "[ab]a"
$(Get-Location).Path | Should BeExactly $testPath.FullName
}

Context 'Set-Location with no arguments' {

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