Skip to content

Commit

Permalink
Fix glob to regex conversation to properly handle **/*.suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkak committed Nov 25, 2024
1 parent fc548b3 commit aea7b99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ private static int glob(String glob, int i, int length, String stopChars, String
switch (current) {
case '*':
if (i < length && glob.charAt(i) == '*') {
result.append(".*");
i++;
if (i < length && glob.charAt(i) == '/') {
result.append("([^/]*/)*");
i++;
} else {
result.append(".*");
}
} else {
result.append("[^/]*");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void doubleStar() {
assertMatch("a**/b", Arrays.asList("a/b", "axy/b", "a/x/b"), Arrays.asList("a", "b", "a/bc", "bc/b"));
assertMatch("a**b", Arrays.asList("ab", "axb", "axyb", "a/b", "a/x/b"), Arrays.asList("abc", "1ab"));
assertMatch("a**b**/c", Arrays.asList("axbx/c", "axbx/c", "a/x/xbx/c", "axbx/xxx/c"), Arrays.asList("axbx/cc"));
assertMatch("**/*.txt", Arrays.asList("/test.txt", "test.txt", "/path/to/a.txt", "relative/path/to/a.txt"),
Arrays.asList("/test.py", "test.json", "/path/to/a.js", "relative/path/to/a.exe"));
}

@Test
Expand Down

0 comments on commit aea7b99

Please sign in to comment.