Skip to content

Commit

Permalink
Fix bug in glob pattern matching (#3657)
Browse files Browse the repository at this point in the history
* add failing test case for glob pattern

* fix comparison bug
  • Loading branch information
Wallman authored Nov 3, 2023
1 parent 2d1a536 commit d93c2d9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rewrite-core/src/main/java/org/openrewrite/PathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static boolean matchesGlob(String pattern, String path) {
}
if (pathIdxStart > pathIdxEnd) {
// Path exhausted
for (int i = pattIdxStart; i < pattIdxEnd; i++) {
for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
if (!pattTokens[i].equals("**")) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions rewrite-core/src/test/java/org/openrewrite/PathUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ void globMatching() {
assertThat(matchesGlob(path("a/b/test.txt"), "a/**/*.txt")).isTrue();
assertThat(matchesGlob(path("a/b/test.txt"), "a/**/test.*")).isTrue();
assertThat(matchesGlob(path("a/b/test.txt"), "a/**/*.*")).isTrue();
assertThat(matchesGlob(path("a-test/a-test/test.txt"), "**/*-test/*-test/test.txt")).isTrue();
assertThat(matchesGlob(path("a-test/test.txt"), "**/*-test/*-test/test.txt")).isFalse();
}

private static Path path(String path) {
Expand Down

0 comments on commit d93c2d9

Please sign in to comment.