Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 77359 invoked from network); 12 Dec 2007 09:32:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Dec 2007 09:32:15 -0000 Received: (qmail 12972 invoked by uid 500); 12 Dec 2007 09:32:04 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 12941 invoked by uid 500); 12 Dec 2007 09:32:04 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 12932 invoked by uid 99); 12 Dec 2007 09:32:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Dec 2007 01:32:04 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Dec 2007 09:31:51 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 77F0A1A9832; Wed, 12 Dec 2007 01:31:54 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: sling-commits@incubator.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071212093154.77F0A1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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();