diff options
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java | 14 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java | 11 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java b/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java index 441571ef3d..11d88cd324 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java @@ -252,7 +252,21 @@ public final class UnixGlob { char c = pattern.charAt(i); switch(c) { case '*': + int toIncrement = 0; + if (len > i + 1 && pattern.charAt(i + 1) == '*') { + // The pattern '**' is interpreted to match 0 or more directory separators, not 1 or + // more. We skip the next * and then find a trailing/leading '/' and get rid of it. + toIncrement = 1; + if (len > i + 2 && pattern.charAt(i + 2) == '/') { + // We have '**/' -- skip the '/'. + toIncrement = 2; + } else if (len == i + 2 && i > 0 && pattern.charAt(i - 1) == '/') { + // We have '/**' -- remove the '/'. + regexp.delete(regexp.length() - 1, regexp.length()); + } + } regexp.append(".*"); + i += toIncrement; break; case '?': regexp.append('.'); diff --git a/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java b/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java index a751e1becc..97c6109a48 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java @@ -302,6 +302,17 @@ public class GlobTest { } @Test + public void testMatcherMethodRecursiveBelowDir() throws Exception { + FileSystemUtils.createEmptyFile(tmpPath.getRelative("foo/file")); + String pattern = "foo/**/*"; + assertTrue(UnixGlob.matches(pattern, "foo/bar")); + assertTrue(UnixGlob.matches(pattern, "foo/bar/baz")); + assertFalse(UnixGlob.matches(pattern, "foo")); + assertFalse(UnixGlob.matches(pattern, "foob")); + assertTrue(UnixGlob.matches("**/foo", "foo")); + } + + @Test public void testMultiplePatternsWithOverlap() throws Exception { assertGlobMatchesAnyOrder(Lists.newArrayList("food", "foo?"), "food", "fool"); |