From 1596c5cd3c46c01123ced7e94476f482e61c6e37 Mon Sep 17 00:00:00 2001 From: "Mathias R. Jessen" Date: Sat, 2 May 2020 21:22:26 +0200 Subject: [PATCH 1/4] Add ForEach-Object -Parallel path test for wildcard $PWD `ForEach-Object -Parallel` should work just the same when $PWD has wildcard characters in their names --- .../Foreach-Object-Parallel.Tests.ps1 | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 index 83293e15e17..df3ecb03c16 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 @@ -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 From 323cceba195e8774dd73b11173ea10db86a888ba Mon Sep 17 00:00:00 2001 From: "Mathias R. Jessen" Date: Sat, 2 May 2020 21:43:55 +0200 Subject: [PATCH 2/4] Fix #12428 incorrect literal path handling --- src/System.Management.Automation/engine/hostifaces/PSTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/hostifaces/PSTask.cs b/src/System.Management.Automation/engine/hostifaces/PSTask.cs index 0c63c2a0b76..7df3c3363f1 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSTask.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSTask.cs @@ -447,7 +447,7 @@ public void Start(Runspace runspace) try { Runspace.DefaultRunspace = runspace; - runspace.ExecutionContext.SessionState.Internal.SetLocation(_currentLocationPath); + runspace.ExecutionContext.SessionState.Internal.SetLocation(_currentLocationPath, new CmdletProviderContext(runspace.ExecutionContext){ SuppressWildcardExpansion = true }); } catch (DriveNotFoundException) { From 7300d82d498cd2556944b46033e04be165b005db Mon Sep 17 00:00:00 2001 From: "Mathias R. Jessen" Date: Mon, 4 May 2020 21:59:16 +0200 Subject: [PATCH 3/4] Update test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 Co-authored-by: Joel Sallow (/u/ta11ow) <32407840+vexx32@users.noreply.github.com> --- .../Foreach-Object-Parallel.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 index df3ecb03c16..47424f41b59 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 @@ -120,8 +120,8 @@ Describe 'ForEach-Object -Parallel Basic Tests' -Tags 'CI' { finally { Set-Location -Path $oldLocation - if($drive -is [System.IO.DirectoryInfo]){ - $drive |Remove-Item -Force + if ($drive -is [System.IO.DirectoryInfo]) { + $drive | Remove-Item -Force } } } From 9aa271080c89f6348985c16594963226de418405 Mon Sep 17 00:00:00 2001 From: "Mathias R. Jessen" Date: Tue, 5 May 2020 01:37:18 +0200 Subject: [PATCH 4/4] Fix style issues --- .../engine/hostifaces/PSTask.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/hostifaces/PSTask.cs b/src/System.Management.Automation/engine/hostifaces/PSTask.cs index 7df3c3363f1..fe42bd55d24 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSTask.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSTask.cs @@ -447,7 +447,12 @@ public void Start(Runspace runspace) try { Runspace.DefaultRunspace = runspace; - runspace.ExecutionContext.SessionState.Internal.SetLocation(_currentLocationPath, new CmdletProviderContext(runspace.ExecutionContext){ SuppressWildcardExpansion = true }); + 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) {