Ensure DataBinder can bind constructor with a Map with simple values
This change ensures that DataBinder can bind constructor with a Map parameter that has no nested properties, but just simple values like a String: `someMap[0]=exampleString`. Integration tests have been added to cover similar cases that use the ServletRequestDataBinder. Closes gh-34043
This commit is contained in:
@@ -1080,7 +1080,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
||||
}
|
||||
int startIdx = paramPath.length() + 1;
|
||||
int endIdx = name.indexOf(']', startIdx);
|
||||
String nestedPath = name.substring(0, endIdx + 2);
|
||||
String nestedPath = ((name.length() > endIdx + 1) ? name.substring(0, endIdx + 2) : "");
|
||||
boolean quoted = (endIdx - startIdx > 2 && name.charAt(startIdx) == '\'' && name.charAt(endIdx - 1) == '\'');
|
||||
String key = (quoted ? name.substring(startIdx + 1, endIdx - 1) : name.substring(startIdx, endIdx));
|
||||
if (map == null) {
|
||||
@@ -1114,7 +1114,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
||||
SortedSet<Integer> indexes = null;
|
||||
for (String name : valueResolver.getNames()) {
|
||||
if (name.startsWith(paramPath + "[")) {
|
||||
int endIndex = name.indexOf(']', paramPath.length() + 2);
|
||||
int endIndex = name.indexOf(']', paramPath.length() + 1);
|
||||
String rawIndex = name.substring(paramPath.length() + 1, endIndex);
|
||||
int index = Integer.parseInt(rawIndex);
|
||||
indexes = (indexes != null ? indexes : new TreeSet<>());
|
||||
|
||||
Reference in New Issue
Block a user