Skip to content

Conversation

@pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Aug 2, 2019

Fixes #9510


Description

Binding for IFormFile does not work correctly when the form file is nested but no sibling properties are specified.

Customer Impact

This allows a fairly narrow set of model binding scenarios where form files are posted to be bound correctly.

Regression

We had a regression in 2.2 that was fixed in 3.0. However, this was identified as one of the scenarios that wasn't correctly addressed.

Risk

Medium. Model binding changes have a fairly large test area, however we have a fair bit of test in this area.

@pranavkm pranavkm requested review from dougbu and rynowak August 2, 2019 23:57
@pranavkm pranavkm added the ask-mode This issue / PR is a patch candidate which we will bar-check internally before patching it. label Aug 3, 2019
Copy link
Contributor

@dougbu dougbu left a comment

Choose a reason for hiding this comment

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

Not sure about this change and I'd like to discuss on Monday. Having a value provider for a greedy BindingSource blurs lines we've been careful about in the past (and hit issues when we weren't). Seems likely to change semantics, admittedly in ways our existing tests didn't catch.

@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Aug 5, 2019
@pranavkm
Copy link
Contributor Author

pranavkm commented Aug 6, 2019

Added some more tests based on our discussion.

/// specifically responds to <see cref="ContainsPrefix(string)"/> queries. This allows the model binding system to
/// recurse in to deeply nested object graphs with only values for form files.
/// </remarks>
public sealed class FormFileValueProvider : IValueProvider
Copy link
Member

Choose a reason for hiding this comment

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

What motivated the choice to make this separate from FormValueProvider? Is the idea that someone could remove this value provider if they don't want it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that was one of the reasons. The other reason is that FormValueProvider is meant to be derived, and it now makes user code much more complicated since they now have to track two separate prefix groups.

var request = context.ActionContext.HttpContext.Request;
if (request.HasFormContentType)
{
// Allocating a Task only when the body is multipart form.
Copy link
Member

Choose a reason for hiding this comment

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

This comment isn't super duper accurate. HasFormContentType will be true for both form content types, not just multipart.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, I changed the code, forgot to update the comment.


<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RootNamespace>Microsoft.AspNetCore.Mvc</RootNamespace>
Copy link
Member

Choose a reason for hiding this comment

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

Thanks 👏 for 👏 doing 👏 this

Copy link
Contributor

@dougbu dougbu left a comment

Choose a reason for hiding this comment

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

Small question and a nit but it's up to you whether another test is needed. Integration test coverage looks good!

{
UpdateRequest(request, data + 1, "FormFiles[0]");
AddFormFile(request, data + 2, "FormFiles[1]");
AddFormFile(request, data + 3, "FormFiles[1]");
Copy link
Contributor

Choose a reason for hiding this comment

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

Does anything different happen if the files are explicitly named e.g. "FormFiles[0][0]", "FormFiles[1][0]" and "FormFiles[1][1]"?

@pranavkm pranavkm force-pushed the prkrishn/form-file branch from 4400ef7 to bc554e7 Compare August 7, 2019 16:44
@pranavkm pranavkm force-pushed the prkrishn/form-file branch from bc554e7 to fb59968 Compare August 7, 2019 21:53
@mkArtakMSFT
Copy link
Contributor

@aspnet-hello
Copy link

This comment was made automatically. If there is a problem contact aspnetcore-build@microsoft.com.

I've triaged the above build. I've created/commented on the following issue(s)
https://github.com/aspnet/AspNetCore-Internal/issues/2948

@pranavkm pranavkm merged commit d6d4bb2 into release/3.0 Aug 8, 2019
@ghost ghost deleted the prkrishn/form-file branch August 8, 2019 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates ask-mode This issue / PR is a patch candidate which we will bar-check internally before patching it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants