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 <robinfriedmann.rf@gmail.com>
  • Loading branch information
robinf95 committed Feb 5, 2024
1 parent d0bb649 commit c154bd7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 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 @@ -46,7 +48,7 @@
public class FilterPath {

static final FilterPath EMPTY = new FilterPath();

private static final Logger logger = LogManager.getLogger(FilterPath.class);
private final String filter;
private final String segment;
private final FilterPath next;
Expand Down Expand Up @@ -103,17 +105,22 @@ public static FilterPath[] compile(Set<String> filters) {
filter = filter.trim();
if (filter.length() > 0) {
paths.add(parse(filter));
} else {
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

package org.opensearch.core.xcontent.filtering;

import java.util.HashSet;
import org.opensearch.common.util.set.Sets;
import org.opensearch.test.OpenSearchTestCase;

import java.util.HashSet;
import java.util.Set;

import static java.util.Collections.singleton;
Expand Down

0 comments on commit c154bd7

Please sign in to comment.