Skip to content

Fix matchesWildcard to safely handle regex metacharacters in feature filter#7151

Draft
Copilot wants to merge 2 commits intoecl-fea-supportfrom
copilot/sub-pr-7124
Draft

Fix matchesWildcard to safely handle regex metacharacters in feature filter#7151
Copilot wants to merge 2 commits intoecl-fea-supportfrom
copilot/sub-pr-7124

Conversation

Copy link
Contributor

Copilot AI commented Mar 15, 2026

matchesWildcard in RepositoryTreeContentProvider only escaped . before calling String.matches(), leaving metacharacters like [, (, \, ?, + unescaped and causing PatternSyntaxException that would break the repository tree UI filter.

Changes

  • Safe pattern construction: Split wildcard pattern on *, apply Pattern.quote() to each literal segment, rejoin with .* — fully isolating user input from regex interpretation
  • Compiled Pattern with CASE_INSENSITIVE flag: Replaces ad-hoc .toLowerCase() calls with a proper case-insensitive Pattern.compile(..., Pattern.CASE_INSENSITIVE).matcher(str).matches()
  • Added java.util.regex.Pattern import
// Before — throws PatternSyntaxException for input like "[eclipse"
String regex = wildcardPattern.replace(".", "\\.").replace("*", ".*");
return str.toLowerCase().matches(regex.toLowerCase());

// After — all metacharacters safely quoted
String[] segments = wildcardPattern.split("\\*", -1);
StringBuilder regex = new StringBuilder();
for (int i = 0; i < segments.length; i++) {
    if (i > 0) regex.append(".*");
    regex.append(Pattern.quote(segments[i]));
}
return Pattern.compile(regex.toString(), Pattern.CASE_INSENSITIVE)
    .matcher(str).matches();

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…rn.quote

Co-authored-by: peterkir <250545+peterkir@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 15, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • bndtools.jfrog.io
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -Xms1024m -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en (dns block)
  • scans-in.gradle.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -Xms1024m -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] [WIP] Address feedback on Eclipse Features support PR Fix matchesWildcard to safely handle regex metacharacters in feature filter Mar 15, 2026
Copilot AI requested a review from peterkir March 15, 2026 20:05
return str.toLowerCase()
.matches(regex.toLowerCase());
// Split on '*', quote each segment, then join with '.*'
String[] segments = wildcardPattern.split("\\*", -1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should reuse theaQute.libg.glob.Glob class which is used in lots of other places for wildcard filtering: e.g.

aQute.bnd.osgi.repository.BridgeRepository.list(String)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants