Commit d84bcdb
committed
Optimize prefixed parameters when assembling model name.
Added an option to optimize model names where the model name is the same
as one of its properties when binding the model name. This should only
be used when this is the desired behavior. Tests have been added to
assert this behavior when passing parameters whose model name is the
same as the property to be bound.
This was introduced to allow circumventing the bug where the parameter
name is the same as the name of one of its properties, causing the
model to trick the PrefixContainer into considering that parameter
as prefixed (model.property), even when it is not.
```C#
class SomeClass
{
public string Parameter { get; set; } = "";
}
```
and later we define the model name as parameter (e.g in a ActionMethod for example)
```C#
public IActionResult SomeEndpoint([FromQuery] SomeClass parameter) { /* elided */ }
```
internally, when we pass the query "?parameter=somecoolparametervalue", it will classify
it as prefixed (parameter.Parameter instead of only parameter), because of the internal
logic of PrefixContainer. However, it is not prefixed, so later on when it try to bind the
key (the keys from the query, in this case parameter) with the internal keys (wrong classified
as parameter.Parameter) the ModelBinder would not find an valid candidate for matching with the
key.
Now the optimization option allows to treat the modelName and the propertyName with only one if
both are equal.1 parent 45635b6 commit d84bcdb
File tree
4 files changed
+49
-3
lines changed- src/Mvc
- Mvc.Core/src
- ModelBinding
- Binders
- test/Mvc.IntegrationTests
4 files changed
+49
-3
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
367 | | - | |
| 367 | + | |
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
62 | 74 | | |
63 | 75 | | |
64 | 76 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2190 | 2190 | | |
2191 | 2191 | | |
2192 | 2192 | | |
2193 | | - | |
| 2193 | + | |
2194 | 2194 | | |
2195 | 2195 | | |
2196 | 2196 | | |
| |||
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
99 | 133 | | |
100 | 134 | | |
101 | 135 | | |
| |||
0 commit comments