From 80c4a2c17b35f7620af43d3883d4b14ee24c73f1 Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Mon, 30 Apr 2018 17:04:24 -0500 Subject: [PATCH 1/3] [Feature] Quote Multipart Field names --- .../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 435eafb79b8..581baee85b5 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 @@ private void AddMultipartContent(object fieldName, object fieldValue, MultipartF 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 @@ private StringContent GetMultipartStringContent(Object fieldName, Object fieldVa 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 @@ private StreamContent GetMultipartStreamContent(Object fieldName, Stream stream) 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; } From 281915103fa7610a85a981e83f1c38a9be579c17 Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Tue, 1 May 2018 03:11:48 -0500 Subject: [PATCH 2/3] [feature] empty commit. re-run CI From ae4207eb6d2c950c99202334bba2efe37767fd43 Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Thu, 3 May 2018 08:03:25 -0500 Subject: [PATCH 3/3] [Feature] Change $"" to + --- .../utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs | 6 +++--- 1 file changed, 3 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 581baee85b5..bafa871187e 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 @@ -1818,7 +1818,7 @@ private StringContent GetMultipartStringContent(Object fieldName, Object fieldVa { var contentDisposition = new ContentDispositionHeaderValue("form-data"); // .NET does not enclose field names in quotes, however, modern browsers and curl do. - contentDisposition.Name = $"\"{LanguagePrimitives.ConvertTo(fieldName)}\""; + contentDisposition.Name = "\"" + LanguagePrimitives.ConvertTo(fieldName) + "\""; var result = new StringContent(LanguagePrimitives.ConvertTo(fieldValue)); result.Headers.ContentDisposition = contentDisposition; @@ -1835,7 +1835,7 @@ private StreamContent GetMultipartStreamContent(Object fieldName, Stream stream) { var contentDisposition = new ContentDispositionHeaderValue("form-data"); // .NET does not enclose field names in quotes, however, modern browsers and curl do. - contentDisposition.Name = $"\"{LanguagePrimitives.ConvertTo(fieldName)}\""; + contentDisposition.Name = "\"" + LanguagePrimitives.ConvertTo(fieldName) + "\""; var result = new StreamContent(stream); result.Headers.ContentDisposition = contentDisposition; @@ -1853,7 +1853,7 @@ private StreamContent GetMultipartFileContent(Object fieldName, FileInfo file) { var result = GetMultipartStreamContent(fieldName: fieldName, stream: new FileStream(file.FullName, FileMode.Open)); // .NET does not enclose field names in quotes, however, modern browsers and curl do. - result.Headers.ContentDisposition.FileName = $"\"{file.Name}\""; + result.Headers.ContentDisposition.FileName = "\"" + file.Name + "\""; return result; }