Skip to content

Commit

Permalink
Wrap filename and param name in quotes for disposition
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Jan 24, 2022
1 parent bc0850c commit 6c7b73b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/RestSharp/Request/RequestContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void AddFiles() {
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse(file.ContentType);

fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") {
Name = file.Name,
FileName = file.FileName
Name = $"\"{file.Name}\"",
FileName = $"\"{file.FileName}\""
};
mpContent.Add(fileContent, file.Name, file.FileName);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ void AddBody(bool hasPostParameters) {
// here we must use multipart form data
var mpContent = Content as MultipartFormDataContent ?? new MultipartFormDataContent();
var ct = bodyContent.Headers.ContentType?.MediaType;
var name = bodyParameter!.Name.IsEmpty() ? ct : bodyParameter!.Name;
var name = bodyParameter!.Name.IsEmpty() ? ct : bodyParameter.Name;

if (name.IsEmpty())
mpContent.Add(bodyContent);
Expand Down
2 changes: 1 addition & 1 deletion test/RestSharp.Tests.Integrated/MultipartFormDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public MultipartFormDataTests(ITestOutputHelper output) {
const string ExpectedFileAndBodyRequestContent =
"--{0}" +
$"{LineBreak}{KnownHeaders.ContentType}: application/octet-stream" +
$"{LineBreak}{KnownHeaders.ContentDisposition}: form-data; name=fileName; filename=TestFile.txt" +
$"{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" +
Expand Down

0 comments on commit 6c7b73b

Please sign in to comment.