Fixed content-disposition quoted filename bug
This commit is contained in:
parent
d34554e3ff
commit
67b078862e
|
|
@ -62,12 +62,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
|
|
||||||
// If there is an <input type="file" ... /> in the form and is left blank.
|
// If there is an <input type="file" ... /> in the form and is left blank.
|
||||||
if (parsedContentDisposition == null ||
|
if (parsedContentDisposition == null ||
|
||||||
(file.Length == 0 && string.IsNullOrEmpty(parsedContentDisposition.FileName)))
|
(file.Length == 0 &&
|
||||||
|
string.IsNullOrEmpty(HeaderUtilities.RemoveQuotes(parsedContentDisposition.FileName))))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var modelName = parsedContentDisposition.Name;
|
var modelName = HeaderUtilities.RemoveQuotes(parsedContentDisposition.Name);
|
||||||
if (modelName.Equals(bindingContext.ModelName, StringComparison.OrdinalIgnoreCase))
|
if (modelName.Equals(bindingContext.ModelName, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
postedFiles.Add(file);
|
postedFiles.Add(file);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
|
@ -36,6 +37,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
Assert.Equal(2, files.Count);
|
Assert.Equal(2, files.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task FormFileModelBinder_FilesWithQuotedContentDisposition_BindSuccessful()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var formFiles = new FormFileCollection();
|
||||||
|
formFiles.Add(GetMockFormFileWithQuotedContentDisposition("file", "file1.txt"));
|
||||||
|
formFiles.Add(GetMockFormFileWithQuotedContentDisposition("file", "file2.txt"));
|
||||||
|
var httpContext = GetMockHttpContext(GetMockFormCollection(formFiles));
|
||||||
|
var bindingContext = GetBindingContext(typeof(IEnumerable<IFormFile>), httpContext);
|
||||||
|
var binder = new FormFileModelBinder();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await binder.BindModelAsync(bindingContext);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.True(result);
|
||||||
|
var files = Assert.IsAssignableFrom<IList<IFormFile>>(bindingContext.Model);
|
||||||
|
Assert.Equal(2, files.Count);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task FormFileModelBinder_ExpectSingleFile_BindFirstFile()
|
public async Task FormFileModelBinder_ExpectSingleFile_BindFirstFile()
|
||||||
{
|
{
|
||||||
|
|
@ -169,6 +190,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
.Returns(string.Format("form-data; name={0}; filename={1}", modelName, filename));
|
.Returns(string.Format("form-data; name={0}; filename={1}", modelName, filename));
|
||||||
return formFile.Object;
|
return formFile.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IFormFile GetMockFormFileWithQuotedContentDisposition(string modelName, string filename)
|
||||||
|
{
|
||||||
|
var formFile = new Mock<IFormFile>();
|
||||||
|
formFile.Setup(f => f.ContentDisposition)
|
||||||
|
.Returns(string.Format("form-data; name=\"{0}\"; filename=\"{1}\"", modelName, filename));
|
||||||
|
return formFile.Object;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue