From d93c2d93dc9e3d2f6c49d4e2e518c01bfdeffe80 Mon Sep 17 00:00:00 2001 From: Daniel Wallman Date: Fri, 3 Nov 2023 18:24:25 +0100 Subject: [PATCH] Fix bug in glob pattern matching (#3657) * add failing test case for glob pattern * fix comparison bug --- rewrite-core/src/main/java/org/openrewrite/PathUtils.java | 2 +- rewrite-core/src/test/java/org/openrewrite/PathUtilsTest.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rewrite-core/src/main/java/org/openrewrite/PathUtils.java b/rewrite-core/src/main/java/org/openrewrite/PathUtils.java index ad7138159de..efcc738ba4e 100755 --- a/rewrite-core/src/main/java/org/openrewrite/PathUtils.java +++ b/rewrite-core/src/main/java/org/openrewrite/PathUtils.java @@ -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; } diff --git a/rewrite-core/src/test/java/org/openrewrite/PathUtilsTest.java b/rewrite-core/src/test/java/org/openrewrite/PathUtilsTest.java index 253762c8b8e..cf599619497 100644 --- a/rewrite-core/src/test/java/org/openrewrite/PathUtilsTest.java +++ b/rewrite-core/src/test/java/org/openrewrite/PathUtilsTest.java @@ -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) {