nonanalou commented on code in PR #30:
URL:
https://github.com/apache/sling-org-apache-sling-xss/pull/30#discussion_r1000559047
##########
src/main/java/org/apache/sling/xss/impl/AntiSamyPolicyAdapter.java:
##########
@@ -222,43 +224,28 @@ public boolean apply(String s) {
private static Predicate<String> matchesPatternsOrLiterals(List<Pattern>
patternList, boolean ignoreCase, List<String> literalList) {
return new Predicate<String>() {
public boolean apply(String s) {
- // check if the string matches to the pattern
- for (Pattern pattern : patternList) {
- if (pattern.matcher(s).matches()) {
- return true;
- }
- }
- // if the pattern does not match it goes through the literals
- for (String string : literalList) {
- s = ignoreCase
- ? s.toLowerCase()
- : s;
- if (string.equals(s)) {
- return true;
- }
- }
- // if it neither matches the patterns nor the literals it
returns false
- return false;
+ // check if the string matches to the pattern or one of the
literal
+ s = ignoreCase ? s.toLowerCase() : s;
+ return matchesToPatterns(patternList).apply(s) ||
literalList.contains(s);
}
};
}
- public AttributePolicy newDynamicAttributePolicy(final Pattern pattern) {
+ public AttributePolicy newDynamicAttributePolicy(final List<Pattern>
patternList, final boolean ignoreCase, final List<String> literalList) {
return new AttributePolicy() {
@Override
public @Nullable String apply(String elementName, String
attributeName, String value) {
- return pattern.matcher(value).matches() ? value : null;
- }
- };
- }
+ if (!literalList.isEmpty() && !patternList.isEmpty()) {
+ return matchesPatternsOrLiterals(patternList,ignoreCase,
literalList).apply(value) ? value : null;
- public AttributePolicy newDynamicAttributePolicy(boolean ignoreCase,
String... allowedValues) {
- final List<String> allowed = Arrays.asList(allowedValues);
- return new AttributePolicy() {
- @Override
- public @Nullable String apply(String elementName, String
attributeName, String uncanonValue) {
- String value = ignoreCase ? uncanonValue.toLowerCase() :
uncanonValue;
- return allowed.contains(value) ? value : null;
+ } else if (!literalList.isEmpty()) {
+ value = ignoreCase ? value.toLowerCase() : value;
Review Comment:
Resolved:
[9f0dbc5](https://github.com/apache/sling-org-apache-sling-xss/pull/30/commits/9f0dbc5a30a90a3949c0dcd7f2bc3b2bac41b420)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]