Skip to content

Commit

Permalink
Fixed path handler
Browse files Browse the repository at this point in the history
  • Loading branch information
EinsamHauer committed Feb 19, 2021
1 parent be7c9c9 commit 2e4a803
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>net.iponweb.disthene.reader</groupId>
<artifactId>disthene-reader</artifactId>
<packaging>jar</packaging>
<version>1.0.20</version>
<version>1.0.21</version>
<name>disthene-reader</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public List<String> getPaths(String tenant, List<String> wildcards) throws TooMu
public String getPathsAsJsonArray(String tenant, String wildcard) throws TooMuchDataExpectedException {
String regEx = WildcardUtil.getPathsRegExFromWildcard(wildcard);

if (!WildcardUtil.regexIsValid(regEx)) {
return "[]";
}

SearchResponse response = client.prepareSearch(indexConfiguration.getIndex())
.setSize(indexConfiguration.getMaxPaths())
.setQuery(QueryBuilders.filteredQuery(
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/net/iponweb/disthene/reader/utils/WildcardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.apache.commons.lang.StringUtils;

import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
* @author Andrei Ivanov
*/
Expand All @@ -17,4 +20,13 @@ public static String getPathsRegExFromWildcard(String wildcard) {
.replace("}", ")").replace(",", "|").replace("?", "[^\\.]");
}

public static boolean regexIsValid(String regex) {
try {
Pattern.compile(regex);
return true;
} catch (PatternSyntaxException exception) {
return false;
}
}

}

0 comments on commit 2e4a803

Please sign in to comment.