You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2016/12/07 07:53:57 UTC
svn commit: r1773017 - in /sling/trunk/bundles/api/src:
main/java/org/apache/sling/api/resource/path/Path.java
test/java/org/apache/sling/api/resource/path/PathTest.java
Author: bdelacretaz
Date: Wed Dec 7 07:53:57 2016
New Revision: 1773017
URL: http://svn.apache.org/viewvc?rev=1773017&view=rev
Log:
SLING-6371 - fix Path.matches() when two glob patterns are compared
Modified:
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/Path.java
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathTest.java
Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/Path.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/Path.java?rev=1773017&r1=1773016&r2=1773017&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/Path.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/Path.java Wed Dec 7 07:53:57 2016
@@ -111,9 +111,11 @@ public class Path implements Comparable<
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
Modified: sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathTest.java?rev=1773017&r1=1773016&r2=1773017&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathTest.java (original)
+++ sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathTest.java Wed Dec 7 07:53:57 2016
@@ -106,4 +106,9 @@ public class PathTest {
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"));
+ }
}