diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs index ee56360e103..b48835ca6e3 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs @@ -763,7 +763,7 @@ private Uri CheckProtocol(Uri uri) private string QualifyFilePath(string path) { - string resolvedFilePath = PathUtils.ResolveFilePath(path, this, false); + string resolvedFilePath = PathUtils.ResolveFilePath(filePath: path, command: this, isLiteralPath: true); return resolvedFilePath; } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index ce3720e49c5..d4743c5f4dd 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -41,14 +41,15 @@ function ExecuteRequestWithOutFile { ) $result = [PSObject]@{Output = $null; Error = $null} - $filePath = Join-Path $TestDrive ((Get-Random).ToString() + ".txt") + # We use '[outfile1]' in the file name to check that OutFile parameter is literal path + $filePath = Join-Path $TestDrive ((Get-Random).ToString() + "[outfile1].txt") try { if ($cmdletName -eq "Invoke-WebRequest") { Invoke-WebRequest -Uri $uri -OutFile $filePath } else { Invoke-RestMethod -Uri $uri -OutFile $filePath } - $result.Output = Get-Content $filePath -Raw -ErrorAction SilentlyContinue + $result.Output = Get-Content -LiteralPath $filePath -Raw -ErrorAction SilentlyContinue } catch { $result.Error = $_ } finally {