Skip to content

Commit 29013b3

Browse files
rstoyanchevcesarhernandezgt
authored andcommitted
Make use of PatternMatchUtils ignoreCase option
Closes spring-projectsgh-34801
1 parent 588216a commit 29013b3

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.Collections;
2424
import java.util.HashMap;
2525
import java.util.List;
26-
import java.util.Locale;
2726
import java.util.Map;
2827

2928
import org.apache.commons.logging.Log;
@@ -460,15 +459,13 @@ public String[] getAllowedFields() {
460459
* <p>Mark fields as disallowed, for example to avoid unwanted
461460
* modifications by malicious users when binding HTTP request parameters.
462461
* <p>Supports {@code "xxx*"}, {@code "*xxx"}, {@code "*xxx*"}, and
463-
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts), as
464-
* well as direct equality.
465-
* <p>The default implementation of this method stores disallowed field patterns
466-
* in {@linkplain PropertyAccessorUtils#canonicalPropertyName(String) canonical}
467-
* form. As of Spring Framework 5.2.21, the default implementation also transforms
468-
* disallowed field patterns to {@linkplain String#toLowerCase() lowercase} to
469-
* support case-insensitive pattern matching in {@link #isAllowed}. Subclasses
470-
* which override this method must therefore take both of these transformations
471-
* into account.
462+
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts),
463+
* as well as direct equality.
464+
* <p>The default implementation of this method stores disallowed field
465+
* patterns in {@linkplain PropertyAccessorUtils#canonicalPropertyName(String)
466+
* canonical} form, and subsequently pattern matching in {@link #isAllowed}
467+
* is case-insensitive. Subclasses that override this method must therefore
468+
* take this transformation into account.
472469
* <p>More sophisticated matching can be implemented by overriding the
473470
* {@link #isAllowed} method.
474471
* <p>Alternatively, specify a list of <i>allowed</i> field patterns.
@@ -483,8 +480,7 @@ public void setDisallowedFields(@Nullable String... disallowedFields) {
483480
else {
484481
String[] fieldPatterns = new String[disallowedFields.length];
485482
for (int i = 0; i < fieldPatterns.length; i++) {
486-
String field = PropertyAccessorUtils.canonicalPropertyName(disallowedFields[i]);
487-
fieldPatterns[i] = field.toLowerCase(Locale.ROOT);
483+
fieldPatterns[i] = PropertyAccessorUtils.canonicalPropertyName(disallowedFields[i]);
488484
}
489485
this.disallowedFields = fieldPatterns;
490486
}
@@ -808,9 +804,9 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
808804
* Determine if the given field is allowed for binding.
809805
* <p>Invoked for each passed-in property value.
810806
* <p>Checks for {@code "xxx*"}, {@code "*xxx"}, {@code "*xxx*"}, and
811-
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts), as
812-
* well as direct equality, in the configured lists of allowed field patterns
813-
* and disallowed field patterns.
807+
* {@code "xxx*yyy"} matches (with an arbitrary number of pattern parts),
808+
* as well as direct equality, in the configured lists of allowed field
809+
* patterns and disallowed field patterns.
814810
* <p>Matching against allowed field patterns is case-sensitive; whereas,
815811
* matching against disallowed field patterns is case-insensitive.
816812
* <p>A field matching a disallowed pattern will not be accepted even if it
@@ -826,8 +822,13 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
826822
protected boolean isAllowed(String field) {
827823
String[] allowed = getAllowedFields();
828824
String[] disallowed = getDisallowedFields();
829-
return ((ObjectUtils.isEmpty(allowed) || PatternMatchUtils.simpleMatch(allowed, field)) &&
830-
(ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field.toLowerCase(Locale.ROOT))));
825+
if (!ObjectUtils.isEmpty(allowed) && !PatternMatchUtils.simpleMatch(allowed, field)) {
826+
return false;
827+
}
828+
if (!ObjectUtils.isEmpty(disallowed)) {
829+
return !PatternMatchUtils.simpleMatchIgnoreCase(disallowed, field);
830+
}
831+
return true;
831832
}
832833

833834
/**

0 commit comments

Comments
 (0)