27
27
import java .util .HashMap ;
28
28
import java .util .HashSet ;
29
29
import java .util .List ;
30
- import java .util .Locale ;
31
30
import java .util .Map ;
32
31
import java .util .Optional ;
33
32
import java .util .Set ;
@@ -543,15 +542,13 @@ public String[] getAllowedFields() {
543
542
* <p>Mark fields as disallowed, for example to avoid unwanted
544
543
* modifications by malicious users when binding HTTP request parameters.
545
544
* <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.
555
552
* <p>More sophisticated matching can be implemented by overriding the
556
553
* {@link #isAllowed} method.
557
554
* <p>Alternatively, specify a list of <i>allowed</i> field patterns.
@@ -569,8 +566,7 @@ public void setDisallowedFields(@Nullable String... disallowedFields) {
569
566
else {
570
567
String [] fieldPatterns = new String [disallowedFields .length ];
571
568
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 ]);
574
570
}
575
571
this .disallowedFields = fieldPatterns ;
576
572
}
@@ -1140,9 +1136,9 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
1140
1136
* Determine if the given field is allowed for binding.
1141
1137
* <p>Invoked for each passed-in property value.
1142
1138
* <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.
1146
1142
* <p>Matching against allowed field patterns is case-sensitive; whereas,
1147
1143
* matching against disallowed field patterns is case-insensitive.
1148
1144
* <p>A field matching a disallowed pattern will not be accepted even if it
@@ -1158,8 +1154,13 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
1158
1154
protected boolean isAllowed (String field ) {
1159
1155
String [] allowed = getAllowedFields ();
1160
1156
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 ;
1163
1164
}
1164
1165
1165
1166
/**
0 commit comments