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 ;
@@ -550,14 +549,13 @@ public String[] getAllowedFields() {
550
549
* <p>Mark fields as disallowed, for example to avoid unwanted
551
550
* modifications by malicious users when binding HTTP request parameters.
552
551
* <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.
561
559
* <p>More sophisticated matching can be implemented by overriding the
562
560
* {@link #isAllowed} method.
563
561
* <p>Alternatively, specify a list of <i>allowed</i> field patterns.
@@ -575,8 +573,7 @@ public void setDisallowedFields(@Nullable String... disallowedFields) {
575
573
else {
576
574
String [] fieldPatterns = new String [disallowedFields .length ];
577
575
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 ]);
580
577
}
581
578
this .disallowedFields = fieldPatterns ;
582
579
}
@@ -1302,9 +1299,9 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
1302
1299
* Determine if the given field is allowed for binding.
1303
1300
* <p>Invoked for each passed-in property value.
1304
1301
* <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.
1308
1305
* <p>Matching against allowed field patterns is case-sensitive; whereas,
1309
1306
* matching against disallowed field patterns is case-insensitive.
1310
1307
* <p>A field matching a disallowed pattern will not be accepted even if it
@@ -1320,8 +1317,13 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
1320
1317
protected boolean isAllowed (String field ) {
1321
1318
String [] allowed = getAllowedFields ();
1322
1319
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 ;
1325
1327
}
1326
1328
1327
1329
/**
0 commit comments