incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r603522 - in /incubator/sling/trunk/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java
Date Wed, 12 Dec 2007 09:31:54 GMT
Author: fmeschbe
Date: Wed Dec 12 01:31:53 2007
New Revision: 603522

URL: http://svn.apache.org/viewvc?rev=603522&view=rev
Log:
ResourcePathIterator should ignore trailing slashes

Modified:
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java?rev=603522&r1=603521&r2=603522&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java
Wed Dec 12 01:31:53 2007
@@ -40,9 +40,21 @@
     private String nextPath;
 
     public ResourcePathIterator(String path) {
-        nextPath = (path != null && path.length() > 0 && !path.equals("/"))
-                ? path
-                : null;
+        if (path != null) {
+            int i = path.length() - 1;
+            while (i >= 0 && path.charAt(i) == '/') {
+                i--;
+            }
+            if (i < 0) {
+                nextPath = null;
+            } else if (i < path.length() - 1) {
+                nextPath = path.substring(0, i + 1);
+            } else {
+                nextPath = path;
+            }
+        } else {
+            nextPath = null;
+        }
     }
 
     public boolean hasNext() {

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java?rev=603522&r1=603521&r2=603522&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java
Wed Dec 12 01:31:53 2007
@@ -65,6 +65,34 @@
         assertEquals("/root/child", rpi.next());
         assertEquals("/root", rpi.next());
         assertFalse(rpi.hasNext());
+        
+        try {
+            rpi.next();
+            fail("Expected NoSuchElementException after end of iterator");
+        } catch (NoSuchElementException nsee) {
+            // expected
+        }
+    }
+    
+    public void testSlashedTrailingSlash1() {
+        ResourcePathIterator rpi = new ResourcePathIterator("/root/child/");
+        assertEquals("/root/child", rpi.next());
+        assertEquals("/root", rpi.next());
+        assertFalse(rpi.hasNext());
+        
+        try {
+            rpi.next();
+            fail("Expected NoSuchElementException after end of iterator");
+        } catch (NoSuchElementException nsee) {
+            // expected
+        }
+    }
+    
+    public void testSlashedTrailingSlash2() {
+        ResourcePathIterator rpi = new ResourcePathIterator("/root/child//");
+        assertEquals("/root/child", rpi.next());
+        assertEquals("/root", rpi.next());
+        assertFalse(rpi.hasNext());
 
         try {
             rpi.next();



Mime
View raw message