diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 320961e16..de5ad69f7 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -3229,6 +3229,7 @@ namespace System.Management.Automation.Runspaces try { + providerContext.SuppressWildcardExpansion = true; context.EngineSessionState.SetLocation(Directory.GetCurrentDirectory(), providerContext); } catch (ItemNotFoundException) diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index 91400a5b1..58be89b0a 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -683,3 +683,27 @@ Describe "Pwsh exe resources tests" -Tag CI { $psversiontable.os | Should -MatchExactly "$($osversion.Major).$($osversion.Minor)" } } + +Describe 'Pwsh startup in directories that contain wild cards' -Tag CI { + BeforeAll { + $powershell = Join-Path -Path $PsHome -ChildPath "pwsh" + $dirnames = "[T]est","[Test","T][est","Test" + $testcases = @() + foreach ( $d in $dirnames ) { + $null = New-Item -type Directory -path "${TESTDRIVE}/$d" + $testcases += @{ Dirname = $d } + } + } + + It "pwsh can startup in a directory named " -testcases $testcases { + param ( $dirname ) + try { + Push-Location -LiteralPath "${TESTDRIVE}/${dirname}" + $result = & $powershell -c '(Get-Item .).Name' + $result | Should -BeExactly $dirname + } + finally { + Pop-Location + } + } +}