jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1387524 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
Date Wed, 19 Sep 2012 11:02:47 GMT
Author: mduerig
Date: Wed Sep 19 11:02:46 2012
New Revision: 1387524

URL: http://svn.apache.org/viewvc?rev=1387524&view=rev
Log:
OAK-313: Trailing slash not removed for simple path in JCR to Oak path conversion
Thanks Chetan for the patch

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java?rev=1387524&r1=1387523&r2=1387524&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
Wed Sep 19 11:02:46 2012
@@ -151,9 +151,6 @@ public class NamePathMapperImpl implemen
     }
 
     private String getOakPath(String jcrPath, final boolean keepIndex) {
-        final List<String> elements = new ArrayList<String>();
-        final StringBuilder parseErrors = new StringBuilder();
-
         if ("/".equals(jcrPath)) {
             // avoid the need to special case the root path later on
             return "/";
@@ -180,6 +177,7 @@ public class NamePathMapperImpl implemen
         boolean hasIndexBrackets = false;
         boolean hasColon = false;
         boolean hasNameStartingWithDot = false;
+        boolean hasTrailingSlash = false;
 
         char prev = 0;
         for (int i = 0; i < length; i++) {
@@ -193,6 +191,8 @@ public class NamePathMapperImpl implemen
                 hasColon = true;
             } else if (c == '.' && (prev == 0 || prev == '/')) {
                 hasNameStartingWithDot = true;
+            } else if(c == '/' && i == (length - 1)){
+                hasTrailingSlash = true;
             }
 
             prev = c;
@@ -202,6 +202,9 @@ public class NamePathMapperImpl implemen
         if (!hasNameStartingWithDot && !hasClarkBrackets && !hasIndexBrackets)
{
             if (!hasColon || !hasSessionLocalMappings()) {
                 if (JcrPathParser.validate(jcrPath)) {
+                    if(hasTrailingSlash){
+                        return jcrPath.substring(0, length - 1);
+                    }
                     return jcrPath;
                 }
                 else {
@@ -211,6 +214,9 @@ public class NamePathMapperImpl implemen
             }
         }
 
+        final List<String> elements = new ArrayList<String>();
+        final StringBuilder parseErrors = new StringBuilder();
+
         JcrPathParser.Listener listener = new JcrPathParser.Listener() {
 
             @Override

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java?rev=1387524&r1=1387523&r2=1387524&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
Wed Sep 19 11:02:46 2012
@@ -57,6 +57,12 @@ public class NamePathMapperImplTest {
     }
 
     @Test
+    public void testTrailingSlash() {
+        assertEquals("/oak-foo:bar/oak-quu:qux",npMapper.getOakPath("/foo:bar/quu:qux/"));
+        assertEquals("/a/b/c",npMapper.getOakPath("/a/b/c/"));
+    }
+
+    @Test
     public void testJcrToOak() {
         assertEquals("/", npMapper.getOakPath("/"));
         assertEquals("foo", npMapper.getOakPath("{}foo"));



Mime
View raw message