SLING-6371 - fix Path.matches() when two glob patterns are compared

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1773017 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/api/resource/path/Path.java b/src/main/java/org/apache/sling/api/resource/path/Path.java
index e9515ee..dff8969 100644
--- a/src/main/java/org/apache/sling/api/resource/path/Path.java
+++ b/src/main/java/org/apache/sling/api/resource/path/Path.java
@@ -111,9 +111,11 @@
     public boolean matches(final String otherPath) {
         if ( otherPath.startsWith(GLOB_PREFIX) ) {
             if ( this.isPattern ) {
-                // both are patterns, then they must be equal
+                // both are patterns, then they must be equal.
+                // need to compare Pattern.pattern() as that class does
+                // not implement a semantic equals(...) method
                 final Path oPath = new Path(otherPath);
-                return this.regexPattern.equals(oPath.regexPattern);
+                return this.regexPattern.pattern().equals(oPath.regexPattern.pattern());
             }
 
             // this is path, provided argument is a pattern
diff --git a/src/test/java/org/apache/sling/api/resource/path/PathTest.java b/src/test/java/org/apache/sling/api/resource/path/PathTest.java
index 1c8bd6b..3a9d8aa 100644
--- a/src/test/java/org/apache/sling/api/resource/path/PathTest.java
+++ b/src/test/java/org/apache/sling/api/resource/path/PathTest.java
@@ -106,4 +106,9 @@
         assertTrue(path.matches("/libs/foo"));
         assertFalse(path.matches("/lib"));
     }
+    @Test public void testGlobPatternsMatch() {
+        final Path glob = new Path("glob:/*/foo");
+        assertTrue(glob.matches("glob:/*/foo"));
+        assertFalse(glob.matches("glob:/*/**/foo"));
+    }
 }