jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r677905 - in /jackrabbit/trunk/jackrabbit-jcr-commons/src: main/java/org/apache/jackrabbit/util/Text.java test/java/org/apache/jackrabbit/util/TextTest.java
Date Fri, 18 Jul 2008 13:40:58 GMT
Author: angela
Date: Fri Jul 18 06:40:57 2008
New Revision: 677905

URL: http://svn.apache.org/viewvc?rev=677905&view=rev
Log:
JCR-1669: Text.isDescendant returns false if parent is '/'

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java?rev=677905&r1=677904&r2=677905&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/Text.java
Fri Jul 18 06:40:57 2008
@@ -604,9 +604,9 @@
      *         <code>false</code> otherwise.
      */
     public static boolean isDescendant(String path, String descendant) {
-        return !path.equals(descendant) &&
-                descendant.startsWith(path) &&
-                descendant.charAt(path.length()) == '/';
+        String pattern = path.endsWith("/") ? path : path + "/";
+        return !pattern.equals(descendant) &&
+                descendant.startsWith(pattern);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java?rev=677905&r1=677904&r2=677905&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java
Fri Jul 18 06:40:57 2008
@@ -20,6 +20,10 @@
 import org.apache.jackrabbit.name.IllegalNameException;
 import org.apache.jackrabbit.name.NameFormat;
 
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
 /**
  * Test cases for the Text utility class.
  */
@@ -62,4 +66,41 @@
         checkEscape("%/:[]*'\"|\t\r\n");
     }
 
+    public void testIsDescendant() {
+        String parent = "/";
+        List descendants = new ArrayList();
+        descendants.add("/a");
+        descendants.add("/a/b");
+        for (Iterator it = descendants.iterator(); it.hasNext();) {
+            String desc = it.next().toString();
+            assertTrue(desc + " must be descendant of " + parent, Text.isDescendant(parent,
desc));
+        }
+        List nonDescendants = new ArrayList();
+        nonDescendants.add("/");
+        nonDescendants.add("a");
+        for (Iterator it = nonDescendants.iterator(); it.hasNext();) {
+            String nonDesc = it.next().toString();
+            assertFalse(nonDesc + " isn't a descendant of " + parent,Text.isDescendant(parent,
nonDesc));
+        }
+
+        parent = "/a/b";
+        descendants = new ArrayList();
+        descendants.add("/a/b/c");
+        descendants.add("/a/b/c/");
+        for (Iterator it = descendants.iterator(); it.hasNext();) {
+            String desc = it.next().toString();
+            assertTrue(desc + " must be descendant of " + parent, Text.isDescendant(parent,
desc));
+        }
+        nonDescendants = new ArrayList();
+        nonDescendants.add("/");
+        nonDescendants.add("/a");
+        nonDescendants.add("/a/b");
+        nonDescendants.add("/a/b/");
+        nonDescendants.add("/d");
+        nonDescendants.add("/d/b");
+        for (Iterator it = nonDescendants.iterator(); it.hasNext();) {
+            String nonDesc = it.next().toString();
+            assertFalse(nonDesc + " isn't a descendant of " + parent, Text.isDescendant(parent,
nonDesc));
+        }
+    }
 }



Mime
View raw message