From 1bfd4c936112a2fea8b07a8f390e60952b59c48f Mon Sep 17 00:00:00 2001 From: Robin Friedmann Date: Thu, 1 Feb 2024 15:58:23 +0100 Subject: [PATCH] Refactor FilterPath parse function (#12067) Signed-off-by: Robin Friedmann --- .../core/xcontent/filtering/FilterPath.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/libs/core/src/main/java/org/opensearch/core/xcontent/filtering/FilterPath.java b/libs/core/src/main/java/org/opensearch/core/xcontent/filtering/FilterPath.java index 5389538a8c7dd..d37a6aaaef4fc 100644 --- a/libs/core/src/main/java/org/opensearch/core/xcontent/filtering/FilterPath.java +++ b/libs/core/src/main/java/org/opensearch/core/xcontent/filtering/FilterPath.java @@ -99,32 +99,26 @@ public static FilterPath[] compile(Set filters) { List paths = new ArrayList<>(); for (String filter : filters) { - if (filter != null) { + if (filter != null && !filter.isEmpty()) { filter = filter.trim(); if (filter.length() > 0) { - paths.add(parse(filter, filter)); + paths.add(parse(filter)); } } } return paths.toArray(new FilterPath[0]); } - private static FilterPath parse(final String filter, final String segment) { - int end = segment.length(); + private static FilterPath parse(final String filter) { + String[] segments = filter.split("(?= 0; i--) { + String segment = segments[i].replaceAll("\\\\.", "."); + next = new FilterPath(filter, segment, next); } - return new FilterPath(filter, segment.replaceAll("\\\\.", "."), EMPTY); + + return next; } @Override