Fix path handling bug in PSTask (#12554)

This commit is contained in:
Mathias R. Jessen
2020-05-14 10:24:28 -07:00
committed by GitHub
parent 22e4f19349
commit 3c07aad4bc
2 changed files with 27 additions and 1 deletions
@@ -447,7 +447,12 @@ namespace System.Management.Automation.PSTasks
try
{
Runspace.DefaultRunspace = runspace;
runspace.ExecutionContext.SessionState.Internal.SetLocation(_currentLocationPath);
var context = new CmdletProviderContext(runspace.ExecutionContext)
{
// _currentLocationPath denotes the current path as-is, and should not be attempted expanded.
SuppressWildcardExpansion = true
};
runspace.ExecutionContext.SessionState.Internal.SetLocation(_currentLocationPath, context);
}
catch (DriveNotFoundException)
{
@@ -105,6 +105,27 @@ Describe 'ForEach-Object -Parallel Basic Tests' -Tags 'CI' {
$parallelScriptLocation.Path | Should -BeExactly $PWD.Path
}
It 'Verifies that the current working directory can have wildcards in its name' {
$oldLocation = Get-Location
$wildcardName = New-Item -Path 'TestDrive:\' -Name '[' -ItemType Directory
Set-Location -LiteralPath $wildcardName.FullName
try
{
{ 1..1 | ForEach-Object -Parallel { $PWD } } | Should -Not -Throw
$wildcardPathResult = 1..1 | ForEach-Object -Parallel { $PWD }
$wildcardPathResult.Path | Should -BeExactly $PWD.Path
}
finally
{
Set-Location -Path $oldLocation
if ($drive -is [System.IO.DirectoryInfo]) {
$drive | Remove-Item -Force
}
}
}
It 'Verifies no terminating error if current working drive is not found' {
$oldLocation = Get-Location
try