Skip to content

Commit e41fe16

Browse files
committed
Merge branch '6.2.x'
2 parents 1187bc2 + ee62701 commit e41fe16

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

spring-context/src/main/java/org/springframework/validation/DataBinder.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.HashMap;
2828
import java.util.HashSet;
2929
import java.util.List;
30-
import java.util.Locale;
3130
import java.util.Map;
3231
import java.util.Optional;
3332
import java.util.Set;
@@ -536,14 +535,13 @@ public void setAllowedFields(String @Nullable ... allowedFields) {
536535
* <p>Mark fields as disallowed, for example to avoid unwanted
537536
* modifications by malicious users when binding HTTP request parameters.
538537
* <p>Supports {@code "xxx*"}, {@code "*xxx"}, {@code "*xxx*"}, and
539-
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts), as
540-
* well as direct equality.
541-
* <p>The default implementation of this method stores disallowed field patterns
542-
* in {@linkplain PropertyAccessorUtils#canonicalPropertyName(String) canonical}
543-
* form and also transforms disallowed field patterns to
544-
* {@linkplain String#toLowerCase() lowercase} to support case-insensitive
545-
* pattern matching in {@link #isAllowed}. Subclasses which override this
546-
* method must therefore take both of these transformations into account.
538+
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts),
539+
* as well as direct equality.
540+
* <p>The default implementation of this method stores disallowed field
541+
* patterns in {@linkplain PropertyAccessorUtils#canonicalPropertyName(String)
542+
* canonical} form, and subsequently pattern matching in {@link #isAllowed}
543+
* is case-insensitive. Subclasses that override this method must therefore
544+
* take this transformation into account.
547545
* <p>More sophisticated matching can be implemented by overriding the
548546
* {@link #isAllowed} method.
549547
* <p>Alternatively, specify a list of <i>allowed</i> field patterns.
@@ -561,8 +559,7 @@ public void setDisallowedFields(String @Nullable ... disallowedFields) {
561559
else {
562560
String[] fieldPatterns = new String[disallowedFields.length];
563561
for (int i = 0; i < fieldPatterns.length; i++) {
564-
String field = PropertyAccessorUtils.canonicalPropertyName(disallowedFields[i]);
565-
fieldPatterns[i] = field.toLowerCase(Locale.ROOT);
562+
fieldPatterns[i] = PropertyAccessorUtils.canonicalPropertyName(disallowedFields[i]);
566563
}
567564
this.disallowedFields = fieldPatterns;
568565
}
@@ -1270,9 +1267,9 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
12701267
* Determine if the given field is allowed for binding.
12711268
* <p>Invoked for each passed-in property value.
12721269
* <p>Checks for {@code "xxx*"}, {@code "*xxx"}, {@code "*xxx*"}, and
1273-
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts), as
1274-
* well as direct equality, in the configured lists of allowed field patterns
1275-
* and disallowed field patterns.
1270+
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts),
1271+
* as well as direct equality, in the configured lists of allowed field
1272+
* patterns and disallowed field patterns.
12761273
* <p>Matching against allowed field patterns is case-sensitive; whereas,
12771274
* matching against disallowed field patterns is case-insensitive.
12781275
* <p>A field matching a disallowed pattern will not be accepted even if it
@@ -1288,8 +1285,13 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
12881285
protected boolean isAllowed(String field) {
12891286
String[] allowed = getAllowedFields();
12901287
String[] disallowed = getDisallowedFields();
1291-
return ((ObjectUtils.isEmpty(allowed) || PatternMatchUtils.simpleMatch(allowed, field)) &&
1292-
(ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field.toLowerCase(Locale.ROOT))));
1288+
if (!ObjectUtils.isEmpty(allowed) && !PatternMatchUtils.simpleMatch(allowed, field)) {
1289+
return false;
1290+
}
1291+
if (!ObjectUtils.isEmpty(disallowed)) {
1292+
return !PatternMatchUtils.simpleMatchIgnoreCase(disallowed, field);
1293+
}
1294+
return true;
12931295
}
12941296

12951297
/**

0 commit comments

Comments
 (0)