From f54a0ab03345ef52200ef0e261e2a9bc615a66b5 Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Mon, 7 May 2018 23:18:09 -0500 Subject: [PATCH] Quote Multipart/Form-Data Field Names (#6782) --- .../WebCmdlet/Common/WebRequestPSCmdlet.Common.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 435eafb79b..bafa871187 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 @@ -1817,7 +1817,8 @@ namespace Microsoft.PowerShell.Commands private StringContent GetMultipartStringContent(Object fieldName, Object fieldValue) { var contentDisposition = new ContentDispositionHeaderValue("form-data"); - contentDisposition.Name = LanguagePrimitives.ConvertTo(fieldName); + // .NET does not enclose field names in quotes, however, modern browsers and curl do. + contentDisposition.Name = "\"" + LanguagePrimitives.ConvertTo(fieldName) + "\""; var result = new StringContent(LanguagePrimitives.ConvertTo(fieldValue)); result.Headers.ContentDisposition = contentDisposition; @@ -1833,7 +1834,8 @@ namespace Microsoft.PowerShell.Commands private StreamContent GetMultipartStreamContent(Object fieldName, Stream stream) { var contentDisposition = new ContentDispositionHeaderValue("form-data"); - contentDisposition.Name = LanguagePrimitives.ConvertTo(fieldName); + // .NET does not enclose field names in quotes, however, modern browsers and curl do. + contentDisposition.Name = "\"" + LanguagePrimitives.ConvertTo(fieldName) + "\""; var result = new StreamContent(stream); result.Headers.ContentDisposition = contentDisposition; @@ -1850,7 +1852,8 @@ namespace Microsoft.PowerShell.Commands private StreamContent GetMultipartFileContent(Object fieldName, FileInfo file) { var result = GetMultipartStreamContent(fieldName: fieldName, stream: new FileStream(file.FullName, FileMode.Open)); - result.Headers.ContentDisposition.FileName = file.Name; + // .NET does not enclose field names in quotes, however, modern browsers and curl do. + result.Headers.ContentDisposition.FileName = "\"" + file.Name + "\""; return result; }