diff --git a/src/System.Management.Automation/utils/PathUtils.cs b/src/System.Management.Automation/utils/PathUtils.cs index 2177f89dbb3..59061902c3a 100644 --- a/src/System.Management.Automation/utils/PathUtils.cs +++ b/src/System.Management.Automation/utils/PathUtils.cs @@ -293,7 +293,10 @@ internal static string ResolveFilePath(string filePath, PSCmdlet command, bool i PSDriveInfo drive = null; path = command.SessionState.Path.GetUnresolvedProviderPathFromPSPath( - filePath, cmdletProviderContext, out provider, out drive); + isLiteralPath ? filePath : WildcardPattern.Unescape(filePath), + cmdletProviderContext, + out provider, + out drive); cmdletProviderContext.ThrowFirstErrorOrDoNothing(); if (!provider.NameEquals(command.Context.ProviderNames.FileSystem)) { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 index b438c30a372..c58b7874bdb 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 @@ -24,6 +24,7 @@ Describe "Out-File" -Tags "CI" { $expectedContent = "some test text" $inObject = New-Object psobject -Property @{text=$expectedContent} $testfile = Join-Path -Path $TestDrive -ChildPath outfileTest.txt + $testfileSp = Join-Path -Path $TestDrive -ChildPath "``[outfileTest``].txt" } AfterEach { @@ -91,6 +92,14 @@ Describe "Out-File" -Tags "CI" { $actual[11] | Should -BeNullOrEmpty } + It "Should create the file with correct name when FilePath contains special char" { + Out-File -FilePath $testfile + Out-File -FilePath $testfileSp + + $testfile | Should -Exist + $testfileSp | Should -Exist + } + It "Should limit each line to the specified number of characters when the width switch is used on objects" { Out-File -FilePath $testfile -Width 10 -InputObject $inObject