Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the JXPathFilter
Browse files Browse the repository at this point in the history
kyakdan committed Oct 19, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c655267 commit 32e73bb
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/main/java/org/apache/commons/jxpath/ri/JXPathFilter.java
Original file line number Diff line number Diff line change
@@ -22,22 +22,18 @@

/**
* A filter to be used by JXPath, to evaluate the xpath string values to impose any restrictions.
* This class implements specific filter interfaces, and implements methods in those.
* This class implements specific filter interfaces, and implements methods in those.
* For instance, it JXPathClassFilter interface, which is used to check if any restricted java classes are passed via xpath
* JXPath uses this filter instance when an extension function instance is created.
*/
public class JXPathFilter implements JXPathClassFilter {
private Set<String> allowedClassesList = null;
private final Set<String> allowedClasses;

public JXPathFilter() {
init();
}

public void init() {
this.allowedClasses = new HashSet<>();
final String allowedClasses = System.getProperty("jxpath.class.allow");
if (allowedClasses != null && !allowedClasses.isEmpty()) {
allowedClassesList = new HashSet<>();
allowedClassesList.addAll(Arrays.asList(allowedClasses.split(",")));
this.allowedClasses.addAll(Arrays.asList(allowedClasses.split(",")));
}
}

@@ -50,10 +46,10 @@ public void init() {
*/
@Override
public boolean exposeToXPath(String className) {
if (allowedClassesList == null || allowedClassesList.size() < 1) {
if (allowedClasses.isEmpty()) {
return false;
}

return allowedClassesList.contains(className) || allowedClassesList.contains("*");
return allowedClasses.contains(className) || allowedClasses.contains("*");
}
}

0 comments on commit 32e73bb

Please sign in to comment.