jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1418290 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/namepath/ test/java/org/apache/jackrabbit/oak/namepath/
Date Fri, 07 Dec 2012 12:43:31 GMT
Author: mduerig
Date: Fri Dec  7 12:43:30 2012
New Revision: 1418290

URL: http://svn.apache.org/viewvc?rev=1418290&view=rev
Log:
OAK-498: NamePathMapper should fail on absolute paths escaping root

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
    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/JcrPathParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java?rev=1418290&r1=1418289&r2=1418290&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
Fri Dec  7 12:43:30 2012
@@ -261,6 +261,7 @@ public class JcrPathParser {
 
     public static boolean validate(String jcrPath) {
         Listener listener = new Listener() {
+            int depth;
             boolean hasRoot;
             @Override
             public boolean root() {
@@ -280,7 +281,8 @@ public class JcrPathParser {
 
             @Override
             public boolean parent() {
-                return true;
+                depth--;
+                return !hasRoot || depth >= 0;
             }
 
             @Override
@@ -289,6 +291,7 @@ public class JcrPathParser {
 
             @Override
             public boolean name(String name, int index) {
+                depth++;
                 return true;
             }
 

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=1418290&r1=1418289&r2=1418290&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
Fri Dec  7 12:43:30 2012
@@ -21,6 +21,7 @@ import java.util.List;
 
 import javax.annotation.Nonnull;
 
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -77,7 +78,7 @@ public class NamePathMapperImpl implemen
 
     @Override
     @Nonnull
-    public String getJcrPath(String oakPath) {
+    public String getJcrPath(final String oakPath) {
         final List<String> elements = new ArrayList<String>();
 
         if ("/".equals(oakPath)) {
@@ -103,11 +104,18 @@ public class NamePathMapperImpl implemen
 
             @Override
             public boolean parent() {
-                if (elements.isEmpty() || "..".equals(elements.get(elements.size() - 1)))
{
+                int prevIdx = elements.size() - 1;
+                String prevElem = prevIdx >= 0 ? elements.get(prevIdx) : null;
+
+                if (prevElem == null || PathUtils.denotesParent(prevElem)) {
                     elements.add("..");
                     return true;
                 }
-                elements.remove(elements.size() - 1);
+                if (prevElem.isEmpty()) {
+                    throw new IllegalArgumentException("Absolute path escapes root: " + oakPath);
+                }
+
+                elements.remove(prevElem);
                 return true;
             }
 
@@ -150,7 +158,7 @@ public class NamePathMapperImpl implemen
         return jcrPath.toString();
     }
 
-    private String getOakPath(String jcrPath, final boolean keepIndex) {
+    private String getOakPath(final String jcrPath, final boolean keepIndex) {
         if ("/".equals(jcrPath)) {
             // avoid the need to special case the root path later on
             return "/";
@@ -237,11 +245,19 @@ public class NamePathMapperImpl implemen
 
             @Override
             public boolean parent() {
-                if (elements.isEmpty() || "..".equals(elements.get(elements.size() - 1)))
{
+                int prevIdx = elements.size() - 1;
+                String prevElem = prevIdx >= 0 ? elements.get(prevIdx) : null;
+
+                if (prevElem == null || PathUtils.denotesParent(prevElem)) {
                     elements.add("..");
                     return true;
                 }
-                elements.remove(elements.size() - 1);
+                if (prevElem.isEmpty()) {
+                    parseErrors.append("Absolute path escapes root: ").append(jcrPath);
+                    return false;
+                }
+
+                elements.remove(prevElem);
                 return true;
             }
 

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=1418290&r1=1418289&r2=1418290&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
Fri Dec  7 12:43:30 2012
@@ -22,7 +22,6 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -143,7 +142,6 @@ public class NamePathMapperImplTest {
         }
     }
 
-    @Ignore
     @Test
     public void testInvalidJcrPaths() {
         assertNull(npMapper.getOakPath("//"));
@@ -153,7 +151,6 @@ public class NamePathMapperImplTest {
         assertNull(npMapper.getOakPath("/foo/../.."));
     }
 
-    @Ignore
     @Test
     public void testInvalidOakPaths() {
         getJcrPath("//");
@@ -172,7 +169,6 @@ public class NamePathMapperImplTest {
         }
     }
 
-    @Ignore
     @Test
     public void testValidateInvalidPaths() {
         assertFalse(JcrPathParser.validate("//"));



Mime
View raw message