Skip to content

Commit ee62701

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

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

+18-16
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;
@@ -550,14 +549,13 @@ public String[] getAllowedFields() {
550549
* <p>Mark fields as disallowed, for example to avoid unwanted
551550
* modifications by malicious users when binding HTTP request parameters.
552551
* <p>Supports {@code "xxx*"}, {@code "*xxx"}, {@code "*xxx*"}, and
553-
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts), as
554-
* well as direct equality.
555-
* <p>The default implementation of this method stores disallowed field patterns
556-
* in {@linkplain PropertyAccessorUtils#canonicalPropertyName(String) canonical}
557-
* form and also transforms disallowed field patterns to
558-
* {@linkplain String#toLowerCase() lowercase} to support case-insensitive
559-
* pattern matching in {@link #isAllowed}. Subclasses which override this
560-
* method must therefore take both of these transformations into account.
552+
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts),
553+
* as well as direct equality.
554+
* <p>The default implementation of this method stores disallowed field
555+
* patterns in {@linkplain PropertyAccessorUtils#canonicalPropertyName(String)
556+
* canonical} form, and subsequently pattern matching in {@link #isAllowed}
557+
* is case-insensitive. Subclasses that override this method must therefore
558+
* take this transformation into account.
561559
* <p>More sophisticated matching can be implemented by overriding the
562560
* {@link #isAllowed} method.
563561
* <p>Alternatively, specify a list of <i>allowed</i> field patterns.
@@ -575,8 +573,7 @@ public void setDisallowedFields(@Nullable String... disallowedFields) {
575573
else {
576574
String[] fieldPatterns = new String[disallowedFields.length];
577575
for (int i = 0; i < fieldPatterns.length; i++) {
578-
String field = PropertyAccessorUtils.canonicalPropertyName(disallowedFields[i]);
579-
fieldPatterns[i] = field.toLowerCase(Locale.ROOT);
576+
fieldPatterns[i] = PropertyAccessorUtils.canonicalPropertyName(disallowedFields[i]);
580577
}
581578
this.disallowedFields = fieldPatterns;
582579
}
@@ -1302,9 +1299,9 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
13021299
* Determine if the given field is allowed for binding.
13031300
* <p>Invoked for each passed-in property value.
13041301
* <p>Checks for {@code "xxx*"}, {@code "*xxx"}, {@code "*xxx*"}, and
1305-
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts), as
1306-
* well as direct equality, in the configured lists of allowed field patterns
1307-
* and disallowed field patterns.
1302+
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts),
1303+
* as well as direct equality, in the configured lists of allowed field
1304+
* patterns and disallowed field patterns.
13081305
* <p>Matching against allowed field patterns is case-sensitive; whereas,
13091306
* matching against disallowed field patterns is case-insensitive.
13101307
* <p>A field matching a disallowed pattern will not be accepted even if it
@@ -1320,8 +1317,13 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
13201317
protected boolean isAllowed(String field) {
13211318
String[] allowed = getAllowedFields();
13221319
String[] disallowed = getDisallowedFields();
1323-
return ((ObjectUtils.isEmpty(allowed) || PatternMatchUtils.simpleMatch(allowed, field)) &&
1324-
(ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field.toLowerCase(Locale.ROOT))));
1320+
if (!ObjectUtils.isEmpty(allowed) && !PatternMatchUtils.simpleMatch(allowed, field)) {
1321+
return false;
1322+
}
1323+
if (!ObjectUtils.isEmpty(disallowed)) {
1324+
return !PatternMatchUtils.simpleMatchIgnoreCase(disallowed, field);
1325+
}
1326+
return true;
13251327
}
13261328

13271329
/**

0 commit comments

Comments
 (0)