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 e9d1674
Show file tree
Hide file tree
Showing 2 changed files with 14 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,14 @@ 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"));
assertMatch("foo/**/test.json",
Arrays.asList("foo/a/b/vd/test.json", "foo/test.json", "foo/42/test.json"),
Arrays.asList("/foo/path/to/test.json", "/test.py", "test.json", "/path/foo/test.json", "path/foo/test.json"));
assertMatch("foo/**/*.json",
Arrays.asList("foo/a/b/vd/a.json", "foo/dsa.json", "foo/32/test2.json"),
Arrays.asList("/foo/path/to/aasf.json", "/test.py", "test.json", "/path/foo/test.json", "path/foo/test.json"));
}

@Test
Expand Down

0 comments on commit e9d1674

Please sign in to comment.