diff --git a/src/System.Management.Automation/engine/SessionStateContainer.cs b/src/System.Management.Automation/engine/SessionStateContainer.cs index 66c210d822..aa32e15122 100644 --- a/src/System.Management.Automation/engine/SessionStateContainer.cs +++ b/src/System.Management.Automation/engine/SessionStateContainer.cs @@ -1478,7 +1478,7 @@ namespace System.Management.Automation string originalPath = path; path = Globber.GetProviderPath( - path, + context.SuppressWildcardExpansion ? path : WildcardPattern.Unescape(path), context, out provider, out drive); @@ -2441,7 +2441,7 @@ namespace System.Management.Automation string providerPath = Globber.GetProviderPath( - path, + context.SuppressWildcardExpansion ? path : WildcardPattern.Unescape(path), context, out provider, out drive); diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 index 6a1d791ed2..fa91e5a132 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ChildItem.Tests.ps1 @@ -196,6 +196,22 @@ Describe "Get-ChildItem" -Tags "CI" { } } +Describe "Get-ChildItem with special path" -Tags "CI" { + + BeforeAll { + $bracketDirName = "Test[Dir]" + $bracketDir = "Test``[Dir``]" + $bracketPath = Join-Path $TestDrive $bracketDir + $null = New-Item -Path $TestDrive -Name $bracketDirName -ItemType Directory -Force + } + + It "Should list files in directory with name containing bracket char" { + $null = New-Item -Path $bracketPath -Name file1.txt -ItemType File + $null = New-Item -Path $bracketPath -Name file2.txt -ItemType File + Get-ChildItem -Path $bracketPath | Should -HaveCount 2 + } +} + Describe 'FileSystem Provider Formatting' -Tag "CI","RequireAdminOnWindows" { BeforeAll {