diff --git a/src/RestSharp/Request/RequestContent.cs b/src/RestSharp/Request/RequestContent.cs index 03af0bdcf..affc60618 100644 --- a/src/RestSharp/Request/RequestContent.cs +++ b/src/RestSharp/Request/RequestContent.cs @@ -143,7 +143,7 @@ void AddBody(bool hasPostParameters, BodyParameter bodyParameter) { if (name.IsEmpty()) mpContent.Add(bodyContent); else - mpContent.Add(bodyContent, name); + mpContent.Add(bodyContent, request.MultipartFormQuoteParameters ? $"\"{name}\"" : name); Content = mpContent; } else { diff --git a/src/RestSharp/Request/RestRequest.cs b/src/RestSharp/Request/RestRequest.cs index 7fa87a718..b2f86f6ef 100644 --- a/src/RestSharp/Request/RestRequest.cs +++ b/src/RestSharp/Request/RestRequest.cs @@ -87,10 +87,9 @@ public RestRequest(Uri resource, Method method = Method.Get) /// /// When set to true, parameter values in a multipart form data requests will be enclosed in - /// quotation marks. Default is false. Enable it if the remote endpoint requires parameters - /// to be in quotes (for example, FreshDesk API). + /// quotation marks. Default is true, as per RFC 7578. /// - public bool MultipartFormQuoteParameters { get; set; } + public bool MultipartFormQuoteParameters { get; set; } = true; /// /// When set to true, the form boundary part of the content type will be enclosed in diff --git a/test/RestSharp.Tests.Integrated/MultipartFormDataTests.cs b/test/RestSharp.Tests.Integrated/MultipartFormDataTests.cs index 1d5ee5899..5fba92f84 100644 --- a/test/RestSharp.Tests.Integrated/MultipartFormDataTests.cs +++ b/test/RestSharp.Tests.Integrated/MultipartFormDataTests.cs @@ -31,7 +31,7 @@ public void Dispose() { const string ContentDispositionString = $"{KnownHeaders.ContentDisposition}: form-data;"; const string Expected = - $"--{{0}}{LineBreak}{ContentTypeString}{LineBreak}{ContentDispositionString} name=foo{LineBreak}{LineBreak}bar{LineBreak}" + + $"--{{0}}{LineBreak}{ContentTypeString}{LineBreak}{ContentDispositionString} name=\"foo\"{LineBreak}{LineBreak}bar{LineBreak}" + $"--{{0}}{LineBreak}{ContentTypeString}{LineBreak}{ContentDispositionString} name=\"a name with spaces\"{LineBreak}{LineBreak}somedata{LineBreak}" + $"--{{0}}--{LineBreak}"; @@ -41,7 +41,7 @@ public void Dispose() { $"{LineBreak}{KnownHeaders.ContentDisposition}: form-data; name=\"fileName\"; filename=\"TestFile.txt\"" + $"{LineBreak}{LineBreak}This is a test file for RestSharp.{LineBreak}" + $"--{{0}}{LineBreak}{KnownHeaders.ContentType}: application/json; {CharsetString}" + - $"{LineBreak}{KnownHeaders.ContentDisposition}: form-data; name=controlName" + + $"{LineBreak}{KnownHeaders.ContentDisposition}: form-data; name=\"controlName\"" + $"{LineBreak}{LineBreak}test{LineBreak}" + $"--{{0}}--{LineBreak}"; @@ -199,7 +199,7 @@ public async Task MultipartFormData_Without_File_Creates_A_Valid_RequestBody() { var expectedBody = new[] { ContentTypeString, - $"{ContentDispositionString} name={multipartName}", + $"{ContentDispositionString} name=\"{multipartName}\"", bodyData }; @@ -228,7 +228,7 @@ public async Task PostParameter_contentType_in_multipart_form() { var actual = capturer.Body!.Replace("\n", string.Empty).Split('\r'); actual[1].Should().Be("Content-Type: application/json; charset=utf-8"); - actual[2].Should().Be($"Content-Disposition: form-data; name={parameterName}"); + actual[2].Should().Be($"Content-Disposition: form-data; name=\"{parameterName}\""); actual[4].Should().Be(parameterValue); } } \ No newline at end of file