From a14b672ac76762b67126fb8aff27d65a45651b6e Mon Sep 17 00:00:00 2001 From: David Nestorovic Date: Thu, 24 Apr 2025 11:42:20 +0200 Subject: [PATCH] Escape stars in matching text when fetching hosted only content --- .../CompressedGlobTrie/CompressedGlobTrie.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/CompressedGlobTrie/CompressedGlobTrie.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/CompressedGlobTrie/CompressedGlobTrie.java index d5500fb78fc7..33d8d9072f34 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/CompressedGlobTrie/CompressedGlobTrie.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/resources/CompressedGlobTrie/CompressedGlobTrie.java @@ -352,8 +352,7 @@ public static void finalize(GlobTrieNode root) { */ @Platforms(Platform.HOSTED_ONLY.class) public static List getHostedOnlyContentIfMatched(GlobTrieNode root, String text) { - List> matchedNodes = new ArrayList<>(); - getAllPatterns(root, getPatternParts(text), 0, matchedNodes); + List> matchedNodes = getAllMatchedNodes(root, text); if (matchedNodes.isEmpty()) { /* text cannot be matched */ return null; @@ -368,11 +367,16 @@ public static List getHostedOnlyContentIfMatched(GlobTrieNode root, St * Returns whether given text can be matched with any glob pattern in the Trie or not. */ public static boolean match(GlobTrieNode root, String text) { + return !getAllMatchedNodes(root, text).isEmpty(); + } + + private static List> getAllMatchedNodes(GlobTrieNode root, String text) { /* in this case text is a plain text without special meanings, so stars must be escaped */ String escapedText = escapeAllStars(text); - List> tmp = new ArrayList<>(); - getAllPatterns(root, getPatternParts(escapedText), 0, tmp); - return !tmp.isEmpty(); + List> matchedNodes = new ArrayList<>(); + getAllPatterns(root, getPatternParts(escapedText), 0, matchedNodes); + + return matchedNodes; } private static String escapeAllStars(String text) {