Skip to content

[GR-64531] Escape stars in matching text when fetching hosted only content #11176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ public static <C> void finalize(GlobTrieNode<C> root) {
*/
@Platforms(Platform.HOSTED_ONLY.class)
public static <C> List<C> getHostedOnlyContentIfMatched(GlobTrieNode<C> root, String text) {
List<GlobTrieNode<C>> matchedNodes = new ArrayList<>();
getAllPatterns(root, getPatternParts(text), 0, matchedNodes);
List<GlobTrieNode<C>> matchedNodes = getAllMatchedNodes(root, text);
if (matchedNodes.isEmpty()) {
/* text cannot be matched */
return null;
Expand All @@ -368,11 +367,16 @@ public static <C> List<C> getHostedOnlyContentIfMatched(GlobTrieNode<C> root, St
* Returns whether given text can be matched with any glob pattern in the Trie or not.
*/
public static <C> boolean match(GlobTrieNode<C> root, String text) {
return !getAllMatchedNodes(root, text).isEmpty();
}

private static <C> List<GlobTrieNode<C>> getAllMatchedNodes(GlobTrieNode<C> root, String text) {
/* in this case text is a plain text without special meanings, so stars must be escaped */
String escapedText = escapeAllStars(text);
List<GlobTrieNode<C>> tmp = new ArrayList<>();
getAllPatterns(root, getPatternParts(escapedText), 0, tmp);
return !tmp.isEmpty();
List<GlobTrieNode<C>> matchedNodes = new ArrayList<>();
getAllPatterns(root, getPatternParts(escapedText), 0, matchedNodes);

return matchedNodes;
}

private static String escapeAllStars(String text) {
Expand Down