Skip to content

Commit 9b8293c

Browse files
alexeyzimarevclaude
andcommitted
Quote multipart form parameter names by default (RFC 7578)
Change MultipartFormQuoteParameters default from false to true so that parameter names in Content-Disposition headers are quoted consistently with file parameter names, as required by RFC 7578. Fixes #2271 Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent acdf9af commit 9b8293c

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/RestSharp/Request/RestRequest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ public RestRequest(Uri resource, Method method = Method.Get)
8787

8888
/// <summary>
8989
/// When set to true, parameter values in a multipart form data requests will be enclosed in
90-
/// quotation marks. Default is false. Enable it if the remote endpoint requires parameters
91-
/// to be in quotes (for example, FreshDesk API).
90+
/// quotation marks. Default is true, as per RFC 7578.
9291
/// </summary>
93-
public bool MultipartFormQuoteParameters { get; set; }
92+
public bool MultipartFormQuoteParameters { get; set; } = true;
9493

9594
/// <summary>
9695
/// When set to true, the form boundary part of the content type will be enclosed in

test/RestSharp.Tests.Integrated/MultipartFormDataTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void Dispose() {
3131
const string ContentDispositionString = $"{KnownHeaders.ContentDisposition}: form-data;";
3232

3333
const string Expected =
34-
$"--{{0}}{LineBreak}{ContentTypeString}{LineBreak}{ContentDispositionString} name=foo{LineBreak}{LineBreak}bar{LineBreak}" +
34+
$"--{{0}}{LineBreak}{ContentTypeString}{LineBreak}{ContentDispositionString} name=\"foo\"{LineBreak}{LineBreak}bar{LineBreak}" +
3535
$"--{{0}}{LineBreak}{ContentTypeString}{LineBreak}{ContentDispositionString} name=\"a name with spaces\"{LineBreak}{LineBreak}somedata{LineBreak}" +
3636
$"--{{0}}--{LineBreak}";
3737

@@ -228,7 +228,7 @@ public async Task PostParameter_contentType_in_multipart_form() {
228228

229229
var actual = capturer.Body!.Replace("\n", string.Empty).Split('\r');
230230
actual[1].Should().Be("Content-Type: application/json; charset=utf-8");
231-
actual[2].Should().Be($"Content-Disposition: form-data; name={parameterName}");
231+
actual[2].Should().Be($"Content-Disposition: form-data; name=\"{parameterName}\"");
232232
actual[4].Should().Be(parameterValue);
233233
}
234234
}

0 commit comments

Comments
 (0)