Skip to content

Commit edfcc6f

Browse files
committed
Make use of PatternMatchUtils ignoreCase option
Closes gh-34801
1 parent f93132b commit edfcc6f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

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

+18-17
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;
@@ -543,15 +542,13 @@ public String[] getAllowedFields() {
543542
* <p>Mark fields as disallowed, for example to avoid unwanted
544543
* modifications by malicious users when binding HTTP request parameters.
545544
* <p>Supports {@code "xxx*"}, {@code "*xxx"}, {@code "*xxx*"}, and
546-
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts), as
547-
* well as direct equality.
548-
* <p>The default implementation of this method stores disallowed field patterns
549-
* in {@linkplain PropertyAccessorUtils#canonicalPropertyName(String) canonical}
550-
* form. As of Spring Framework 5.2.21, the default implementation also transforms
551-
* disallowed field patterns to {@linkplain String#toLowerCase() lowercase} to
552-
* support case-insensitive pattern matching in {@link #isAllowed}. Subclasses
553-
* which override this method must therefore take both of these transformations
554-
* into account.
545+
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts),
546+
* as well as direct equality.
547+
* <p>The default implementation of this method stores disallowed field
548+
* patterns in {@linkplain PropertyAccessorUtils#canonicalPropertyName(String)
549+
* canonical} form, and subsequently pattern matching in {@link #isAllowed}
550+
* is case-insensitive. Subclasses that override this method must therefore
551+
* take this transformation into account.
555552
* <p>More sophisticated matching can be implemented by overriding the
556553
* {@link #isAllowed} method.
557554
* <p>Alternatively, specify a list of <i>allowed</i> field patterns.
@@ -569,8 +566,7 @@ public void setDisallowedFields(@Nullable String... disallowedFields) {
569566
else {
570567
String[] fieldPatterns = new String[disallowedFields.length];
571568
for (int i = 0; i < fieldPatterns.length; i++) {
572-
String field = PropertyAccessorUtils.canonicalPropertyName(disallowedFields[i]);
573-
fieldPatterns[i] = field.toLowerCase(Locale.ROOT);
569+
fieldPatterns[i] = PropertyAccessorUtils.canonicalPropertyName(disallowedFields[i]);
574570
}
575571
this.disallowedFields = fieldPatterns;
576572
}
@@ -1140,9 +1136,9 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
11401136
* Determine if the given field is allowed for binding.
11411137
* <p>Invoked for each passed-in property value.
11421138
* <p>Checks for {@code "xxx*"}, {@code "*xxx"}, {@code "*xxx*"}, and
1143-
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts), as
1144-
* well as direct equality, in the configured lists of allowed field patterns
1145-
* and disallowed field patterns.
1139+
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts),
1140+
* as well as direct equality, in the configured lists of allowed field
1141+
* patterns and disallowed field patterns.
11461142
* <p>Matching against allowed field patterns is case-sensitive; whereas,
11471143
* matching against disallowed field patterns is case-insensitive.
11481144
* <p>A field matching a disallowed pattern will not be accepted even if it
@@ -1158,8 +1154,13 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
11581154
protected boolean isAllowed(String field) {
11591155
String[] allowed = getAllowedFields();
11601156
String[] disallowed = getDisallowedFields();
1161-
return ((ObjectUtils.isEmpty(allowed) || PatternMatchUtils.simpleMatch(allowed, field)) &&
1162-
(ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field.toLowerCase(Locale.ROOT))));
1157+
if (!ObjectUtils.isEmpty(allowed) && !PatternMatchUtils.simpleMatch(allowed, field)) {
1158+
return false;
1159+
}
1160+
if (!ObjectUtils.isEmpty(disallowed)) {
1161+
return !PatternMatchUtils.simpleMatchIgnoreCase(disallowed, field);
1162+
}
1163+
return true;
11631164
}
11641165

11651166
/**

0 commit comments

Comments
 (0)