From 2e4a8035e186e248c1113e5b4557e536cd0926d4 Mon Sep 17 00:00:00 2001 From: Andrei Ivanov Date: Fri, 19 Feb 2021 20:45:24 +0300 Subject: [PATCH] Fixed path handler --- pom.xml | 2 +- .../disthene/reader/service/index/IndexService.java | 4 ++++ .../iponweb/disthene/reader/utils/WildcardUtil.java | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3f50c4a6..3426897c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.iponweb.disthene.reader disthene-reader jar - 1.0.20 + 1.0.21 disthene-reader http://maven.apache.org diff --git a/src/main/java/net/iponweb/disthene/reader/service/index/IndexService.java b/src/main/java/net/iponweb/disthene/reader/service/index/IndexService.java index 85f33026..71e27519 100644 --- a/src/main/java/net/iponweb/disthene/reader/service/index/IndexService.java +++ b/src/main/java/net/iponweb/disthene/reader/service/index/IndexService.java @@ -83,6 +83,10 @@ public List getPaths(String tenant, List 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( diff --git a/src/main/java/net/iponweb/disthene/reader/utils/WildcardUtil.java b/src/main/java/net/iponweb/disthene/reader/utils/WildcardUtil.java index f4264eb3..4b7593ff 100644 --- a/src/main/java/net/iponweb/disthene/reader/utils/WildcardUtil.java +++ b/src/main/java/net/iponweb/disthene/reader/utils/WildcardUtil.java @@ -2,6 +2,9 @@ import org.apache.commons.lang.StringUtils; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + /** * @author Andrei Ivanov */ @@ -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; + } + } + }