You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by js...@apache.org on 2024/08/14 10:41:13 UTC
(sling-org-apache-sling-xss) 01/01: SLING-12408 - simplify logic in AntiSamyPolicyAdapter
This is an automated email from the ASF dual-hosted git repository.
jsedding pushed a commit to branch jsedding/SLING-12408-simplify-AntiSamyPolicyAdapter
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-xss.git
commit fa169b48eb5e36060d5bf8f7125586b7a16fdcc0
Author: Julian Sedding <js...@apache.org>
AuthorDate: Tue Jul 2 16:42:43 2024 +0200
SLING-12408 - simplify logic in AntiSamyPolicyAdapter
---
.../sling/xss/impl/AntiSamyPolicyAdapter.java | 28 ++--------------------
1 file changed, 2 insertions(+), 26 deletions(-)
diff --git a/src/main/java/org/apache/sling/xss/impl/AntiSamyPolicyAdapter.java b/src/main/java/org/apache/sling/xss/impl/AntiSamyPolicyAdapter.java
index 5a682a3..4ed52a9 100644
--- a/src/main/java/org/apache/sling/xss/impl/AntiSamyPolicyAdapter.java
+++ b/src/main/java/org/apache/sling/xss/impl/AntiSamyPolicyAdapter.java
@@ -134,23 +134,9 @@ public class AntiSamyPolicyAdapter {
List<String> literalList = attribute.getLiterals();
List<Pattern> patternList = attribute.getPatternList();
- if (!literalList.isEmpty() && !patternList.isEmpty()) {
- // if both, the patterns and the literals are not empty, the value should be checked with them with an OR and not with an AND.
- policyBuilder.allowAttributes(attribute.getName())
+ policyBuilder.allowAttributes(attribute.getName())
.matching(matchesPatternsOrLiterals(patternList, true, literalList))
.onElements(tag.getValue().getName());
- }
- else if (!literalList.isEmpty()) {
- policyBuilder.allowAttributes(attribute.getName())
- .matching(true, literalList.toArray(new String[0]))
- .onElements(tag.getValue().getName());
- policyBuilder.allowAttributes(attribute.getName()).onElements(tag.getValue().getName());
- }
- else if (!patternList.isEmpty()) {
- policyBuilder.allowAttributes(attribute.getName())
- .matching(matchesToPatterns(patternList))
- .onElements(tag.getValue().getName());
- }
}
if (!styleSeen) {
@@ -235,17 +221,7 @@ public class AntiSamyPolicyAdapter {
return new AttributePolicy() {
@Override
public @Nullable String apply(String elementName, String attributeName, String value) {
- if (!literalList.isEmpty() && !patternList.isEmpty()) {
- return matchesPatternsOrLiterals(patternList, ignoreCase, literalList).test(value) ? value : null;
-
- } else if (!literalList.isEmpty()) {
- value = ignoreCase ? value.toLowerCase() : value;
- return literalList.contains(value) ? value : null;
-
- } else if (!patternList.isEmpty()) {
- return matchesToPatterns(patternList).test(value) ? value : null;
- }
- return null;
+ return matchesPatternsOrLiterals(patternList, ignoreCase, literalList).test(value) ? value : null;
}
};
}