-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Treating empty string in form post as null for nullable value types #52499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for your PR, @nvmkpk. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Hi @nvmkpk. If this is not a tell-mode PR, please make sure to follow the instructions laid out in the servicing process document. |
@dotnet-policy-service agree |
@SteveSandersonMS have to think about it. I would look into what MVC does. We should be consistent here. Also, there's no way to differentiate a null value from an empty string if we treat the empty string as null. |
When looked at the form field in the UI, there is no difference between null and empty string right? |
Commenter does not have sufficient privileges for PR 52499 in repo dotnet/aspnetcore |
Can we re-target this PR to main as a first step? |
@javiercn, added e2e tests as well. I would like to see this merged before .net 9 release. I just can't wait another year for this. |
@javiercn, .net 9 rc 1 is out, does that mean this will not be in .net 9? |
Any update on when this will be merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no opposition to taking this change in in the context of form binding in minimal APIs.
@javiercn Thoughts on the Blazor side?
} | ||
else | ||
{ | ||
result = innerResult; | ||
return true; | ||
return TryConvertValue(ref reader, value!, out result!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a null suppression here, perhaps we should add [NotNullWhen] annotations to the FormDataReader.TryGetValue
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
We want to take this, but we want to limit it to primitive types, and not just any |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@nvmkpk thanks for the contribution! |
Thank you @javiercn, will this be available in preview 2 whenever it comes out? |
Just confirmed the fix is in place in .Net Preview 2 and it works very well. It improves Blazor static SSR form binding. |
Adding proper parsing of empty string from form post for a nullable field
The changes treat the empty string as null
Description
Form post sends empty string for an empty input field but
NullableConverter
does not handle that and just uses corresponding non-nullable converter to parse and fails. This PR updates that to convert the empty string to corresponding type's null value.Fixes #52195
Customer Impact
Without these changes, we cannot define an optional value type field (like
DateOnly
) when not using any interactive rendering modes.Regression?
Risk
Verification
Packaging changes reviewed?
When servicing release/2.1
Fixes #52195