Skip to content

Commit

Permalink
Write warn log if Filter is empty; Add comments (opensearch-project#1…
Browse files Browse the repository at this point in the history
…2067)

Signed-off-by: Robin Friedmann <[email protected]>
  • Loading branch information
robinf95 committed Feb 5, 2024
1 parent d0bb649 commit 0be57d1
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.opensearch.core.xcontent.filtering;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.common.Glob;

import java.util.ArrayList;
Expand All @@ -52,6 +54,7 @@ public class FilterPath {
private final FilterPath next;
private final boolean simpleWildcard;
private final boolean doubleWildcard;
private static final Logger logger = LogManager.getLogger(FilterPath.class);

protected FilterPath(String filter, String segment, FilterPath next) {
this.filter = filter;
Expand Down Expand Up @@ -103,17 +106,22 @@ public static FilterPath[] compile(Set<String> filters) {
filter = filter.trim();
if (filter.length() > 0) {
paths.add(parse(filter));
} else {
// write a warn log
logger.warn("Filter is empty!");
}
}
}
return paths.toArray(new FilterPath[0]);
}

private static FilterPath parse(final String filter) {
// Split the filter into segments using a regex that avoids splitting escaped dots.
String[] segments = filter.split("(?<!\\\\)\\.");
FilterPath next = EMPTY;

for (int i = segments.length - 1; i >= 0; i--) {
// Replace escaped dots with actual dots in the current segment.
String segment = segments[i].replaceAll("\\\\.", ".");
next = new FilterPath(filter, segment, next);
}
Expand Down

0 comments on commit 0be57d1

Please sign in to comment.