Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/RestSharp/Request/RestRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ public RestRequest(Uri resource, Method method = Method.Get)

/// <summary>
/// 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.
/// </summary>
public bool MultipartFormQuoteParameters { get; set; }
public bool MultipartFormQuoteParameters { get; set; } = true;
Comment on lines 88 to +92

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Quoting not applied to body parts 🐞 Bug ✓ Correctness

MultipartFormQuoteParameters now defaults to true, but it is only used when adding
GetOrPostParameter parts; BodyParameter parts are still added without applying the quote behavior,
producing inconsistent Content-Disposition formatting within the same multipart request.
Agent Prompt
### Issue description
`MultipartFormQuoteParameters` now defaults to `true`, but it is only used when adding `GetOrPostParameter` parts. Multipart body parts added via `BodyParameter` still call `mpContent.Add(bodyContent, name)` without applying the quote behavior, resulting in mixed quoted/unquoted `Content-Disposition` name parameters.

### Issue Context
The PR intends to quote multipart form parameter names by default, but current implementation only affects one code path.

### Fix Focus Areas
- src/RestSharp/Request/RequestContent.cs[133-147]
- src/RestSharp/Request/RequestContent.cs[159-171]
- test/RestSharp.Tests.Integrated/MultipartFormDataTests.cs[38-46]
- src/RestSharp/Request/RestRequest.cs[88-92]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


/// <summary>
/// When set to true, the form boundary part of the content type will be enclosed in
Expand Down
4 changes: 2 additions & 2 deletions test/RestSharp.Tests.Integrated/MultipartFormDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand Down Expand Up @@ -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);
}
}
Loading