23
23
import java .util .Collections ;
24
24
import java .util .HashMap ;
25
25
import java .util .List ;
26
- import java .util .Locale ;
27
26
import java .util .Map ;
28
27
29
28
import org .apache .commons .logging .Log ;
@@ -460,15 +459,13 @@ public String[] getAllowedFields() {
460
459
* <p>Mark fields as disallowed, for example to avoid unwanted
461
460
* modifications by malicious users when binding HTTP request parameters.
462
461
* <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.
472
469
* <p>More sophisticated matching can be implemented by overriding the
473
470
* {@link #isAllowed} method.
474
471
* <p>Alternatively, specify a list of <i>allowed</i> field patterns.
@@ -483,8 +480,7 @@ public void setDisallowedFields(@Nullable String... disallowedFields) {
483
480
else {
484
481
String [] fieldPatterns = new String [disallowedFields .length ];
485
482
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 ]);
488
484
}
489
485
this .disallowedFields = fieldPatterns ;
490
486
}
@@ -808,9 +804,9 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
808
804
* Determine if the given field is allowed for binding.
809
805
* <p>Invoked for each passed-in property value.
810
806
* <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.
814
810
* <p>Matching against allowed field patterns is case-sensitive; whereas,
815
811
* matching against disallowed field patterns is case-insensitive.
816
812
* <p>A field matching a disallowed pattern will not be accepted even if it
@@ -826,8 +822,13 @@ protected void checkAllowedFields(MutablePropertyValues mpvs) {
826
822
protected boolean isAllowed (String field ) {
827
823
String [] allowed = getAllowedFields ();
828
824
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 ;
831
832
}
832
833
833
834
/**
0 commit comments