From d61ea0369447e78edee0e85c3a7abe9aa48fabc0 Mon Sep 17 00:00:00 2001 From: "James Truher [MSFT]" Date: Thu, 12 Jul 2018 15:10:31 -0700 Subject: [PATCH] Make pwsh able to start in a directory with wildcards in the name (#7240) --- .../engine/InitialSessionState.cs | 1 + test/powershell/Host/ConsoleHost.Tests.ps1 | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 320961e167..de5ad69f78 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 91400a5b12..58be89b0a4 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 + } + } +}