diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/FormFileModelBinder.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/FormFileModelBinder.cs index 79abd05f59..e8796a45b4 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/FormFileModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/FormFileModelBinder.cs @@ -62,12 +62,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // If there is an in the form and is left blank. if (parsedContentDisposition == null || - (file.Length == 0 && string.IsNullOrEmpty(parsedContentDisposition.FileName))) + (file.Length == 0 && + string.IsNullOrEmpty(HeaderUtilities.RemoveQuotes(parsedContentDisposition.FileName)))) { continue; } - var modelName = parsedContentDisposition.Name; + var modelName = HeaderUtilities.RemoveQuotes(parsedContentDisposition.Name); if (modelName.Equals(bindingContext.ModelName, StringComparison.OrdinalIgnoreCase)) { postedFiles.Add(file); diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/FormFileModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/FormFileModelBinderTest.cs index c2a63ce342..68b2f3232a 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/FormFileModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/FormFileModelBinderTest.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; +using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; @@ -36,6 +37,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding 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), httpContext); + var binder = new FormFileModelBinder(); + + // Act + var result = await binder.BindModelAsync(bindingContext); + + // Assert + Assert.True(result); + var files = Assert.IsAssignableFrom>(bindingContext.Model); + Assert.Equal(2, files.Count); + } + [Fact] 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)); return formFile.Object; } + + private static IFormFile GetMockFormFileWithQuotedContentDisposition(string modelName, string filename) + { + var formFile = new Mock(); + formFile.Setup(f => f.ContentDisposition) + .Returns(string.Format("form-data; name=\"{0}\"; filename=\"{1}\"", modelName, filename)); + return formFile.Object; + } } }