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 ;
@@ -536,14 +535,13 @@ public void setAllowedFields(String @Nullable ... allowedFields) {
536
535
* <p>Mark fields as disallowed, for example to avoid unwanted
537
536
* modifications by malicious users when binding HTTP request parameters.
538
537
* <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.
547
545
* <p>More sophisticated matching can be implemented by overriding the
548
546
* {@link #isAllowed} method.
549
547
* <p>Alternatively, specify a list of <i>allowed</i> field patterns.
@@ -561,8 +559,7 @@ public void setDisallowedFields(String @Nullable ... disallowedFields) {
561
559
else {
562
560
String [] fieldPatterns = new String [disallowedFields .length ];
563
561
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 ]);
566
563
}
567
564
this .disallowedFields = fieldPatterns ;
568
565
}
@@ -1270,9 +1267,9 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
1270
1267
* Determine if the given field is allowed for binding.
1271
1268
* <p>Invoked for each passed-in property value.
1272
1269
* <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.
1276
1273
* <p>Matching against allowed field patterns is case-sensitive; whereas,
1277
1274
* matching against disallowed field patterns is case-insensitive.
1278
1275
* <p>A field matching a disallowed pattern will not be accepted even if it
@@ -1288,8 +1285,13 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
1288
1285
protected boolean isAllowed (String field ) {
1289
1286
String [] allowed = getAllowedFields ();
1290
1287
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 ;
1293
1295
}
1294
1296
1295
1297
/**
0 commit comments