Fixes #57637 [FromQuery] Model binding fails in case of propertity with…#66837
Open
FatTigerWang wants to merge 1 commit into
Open
Fixes #57637 [FromQuery] Model binding fails in case of propertity with…#66837FatTigerWang wants to merge 1 commit into
FatTigerWang wants to merge 1 commit into
Conversation
…y with the same name
Contributor
|
Thanks for your PR, @FatTigerWang. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… the same name
Fixes #57637 [FromQuery] Model binding fails
Summary
Fix #57637 —
[FromQuery]model binding fails when the parameter name matches a property name of the complex type model.Root cause: In
ParameterBinder.cs,ContainsPrefix(parameter.Name)returnstrueon a case-insensitive exact match (e.g., query key"Parameter"matches parameter name"parameter"). This incorrectly sets the model prefix to"parameter", causing the complex type binder to look for"parameter.Parameter"instead of just"Parameter".Fix: For complex types, after
ContainsPrefixreturnstrue, additionally verify viaGetKeysFromPrefix()that delimiter-separated sub-keys exist. If none exist (only an exact name match), fall back to empty prefix so properties bind directly.Changes
src/Mvc/Mvc.Core/src/ModelBinding/ParameterBinder.cs— Added complex type check to distinguish property name collisions from true prefix matchessrc/Mvc/Mvc.Core/test/ModelBinding/ParameterBinderTest.cs— Added 3 unit tests covering the fix, prefix usage, and simple type behaviorTest Plan
?Parameter=test) binds correctly with empty prefix?parameter.Parameter=test) still uses parameter name as prefixWant me to create a git commit with this message?