jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1581382 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/
Date Tue, 25 Mar 2014 15:48:54 GMT
Author: angela
Date: Tue Mar 25 15:48:54 2014
New Revision: 1581382

URL: http://svn.apache.org/r1581382
Log:
OAK-1168 : Invalid JCR paths not caught

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
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.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=1581382&r1=1581381&r2=1581382&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
Tue Mar 25 15:48:54 2014
@@ -239,46 +239,49 @@ public class NamePathMapperImpl implemen
         int colon = -1; // index of the last colon in the path
 
         switch (path.charAt(0)) {
-        case '{': // possibly an expanded name
-        case '[': // starts with an identifier
-        case '.': // possibly "." or ".."
-        case ':': // colon as the first character
-            return true;
-        case '/':
-            if (length == 1) {
-                return false; // the root path
-            }
-            slash = 0;
-            break;
-        }
-
-        for (int i = 1; i < length; i++) {
-            switch (path.charAt(i)) {
             case '{': // possibly an expanded name
-            case '[': // possibly an index
+            case '[': // starts with an identifier
+            case '.': // possibly "." or ".."
+            case ':': // colon as the first character
                 return true;
-            case '.':
-                if (i == slash + 1) {
-                    return true; // possibly "." or ".."
-                }
-                break;
-            case ':':
-                if (i == slash + 1              // "x/:y"
-                        || i == colon + i       // "x::y"
-                        || colon > slash        // "x:y:z"
-                        || i + 1 == length) {   // "x:"
-                    return true;
-                }
-                colon = i;
-                break;
             case '/':
-                if (i == slash + 1              // "x//y"
-                        || i == colon + i       // "x:/y"
-                        || i + 1 == length) {   // "x/"
-                    return true;
+                if (length == 1) {
+                    return false; // the root path
                 }
-                slash = i;
+                slash = 0;
                 break;
+        }
+
+        for (int i = 1; i < length; i++) {
+            switch (path.charAt(i)) {
+                case '{': // possibly an expanded name
+                case '[': // possibly an index
+                case ']': // illegal character if not part of index
+                case '|': // illegal character
+                case '*': // illegal character
+                    return true;
+                case '.':
+                    if (i == slash + 1) {
+                        return true; // possibly "." or ".."
+                    }
+                    break;
+                case ':':
+                    if (i == slash + 1              // "x/:y"
+                            || i == colon + i       // "x::y"
+                            || colon > slash        // "x:y:z"
+                            || i + 1 == length) {   // "x:"
+                        return true;
+                    }
+                    colon = i;
+                    break;
+                case '/':
+                    if (i == slash + 1              // "x//y"
+                            || i == colon + i       // "x:/y"
+                            || i + 1 == length) {   // "x/"
+                        return true;
+                    }
+                    slash = i;
+                    break;
             }
         }
 

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=1581382&r1=1581381&r2=1581382&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
Tue Mar 25 15:48:54 2014
@@ -16,23 +16,21 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-
 import javax.jcr.RepositoryException;
 
 import com.google.common.collect.ImmutableMap;
-
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
 public class NamePathMapperImplTest {
 
     private static final Map<String, String> GLOBAL = ImmutableMap.of(
@@ -167,7 +165,10 @@ public class NamePathMapperImplTest {
                 "/foo/../..",
                 "foo::bar",
                 "foo:bar:baz",
-//                "foo:bar]baz",  FIXME OAK-1168
+                "foo:bar]baz",
+                "foo:bar[baz",
+                "foo:bar|baz",
+                "foo:bar*baz"
         };
 
         NamePathMapper[] mappers = {

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1581382&r1=1581381&r2=1581382&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Tue Mar 25 15:48:54 2014
@@ -18,16 +18,6 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
-import static java.util.Arrays.asList;
-import static org.apache.jackrabbit.commons.JcrUtils.getChildNodes;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
-
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -38,8 +28,8 @@ import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
-
 import javax.jcr.Binary;
 import javax.jcr.GuestCredentials;
 import javax.jcr.ImportUUIDBehavior;
@@ -66,6 +56,7 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeTemplate;
 
+import com.google.common.collect.ImmutableList;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.api.JackrabbitNode;
 import org.apache.jackrabbit.api.JackrabbitRepository;
@@ -80,6 +71,15 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
+import static java.util.Arrays.asList;
+import static org.apache.jackrabbit.commons.JcrUtils.getChildNodes;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
 public class RepositoryTest extends AbstractRepositoryTest {
     private static final String TEST_NODE = "test_node";
     private static final String TEST_PATH = '/' + TEST_NODE;
@@ -349,30 +349,97 @@ public class RepositoryTest extends Abst
         root.getNode("/foo");
     }
 
-    @Test(expected = RepositoryException.class)
-    public void testExceptionThrownForInvalidPath() throws RepositoryException {
+    @Test
+    public void testInvalidPath() throws RepositoryException {
         Session session = getAdminSession();
-        session.itemExists("//jcr:content");
+
+        List<String> invalid = ImmutableList.of(
+                "//jcr:content",
+                "/jcr:con]ent",
+                "/con]ent",
+                "/jcr:con*ent",
+                "/con*ent",
+                "/jcr:con|ent",
+                "/con|ent");
+        for (String path : invalid) {
+            try {
+                session.itemExists(path);
+                fail("Invalid path " + path);
+            } catch (RepositoryException e) {
+                // success
+            }
+        }
+
+        session.setNamespacePrefix("foo", "http://foo.bar");
+        for (String path : invalid) {
+            try {
+                session.itemExists(path);
+                fail("Invalid path " + path);
+            } catch (RepositoryException e) {
+                // success
+            }
+        }
     }
 
     @Test
-    @Ignore("OAK-1174")  // FIXME OAK-1174
     public void testInvalidName() throws RepositoryException {
-        Session session = getAdminSession();
+        List<String> invalid = ImmutableList.of(
+                "/jcr:content",
+                "/content",
+                "jcr:con/ent",
+                "jc/r:content",
+                "con/ent",
+
+                "jcr:con:ent",
+
+                "jcr:content[1]",
+                "content[1]",
+                "jcr:conten[t]",
+                "conten[t]",
+
+                "jcr:con[]ent",
+                "jcr[]:content",
+                "con[]ent",
+                "jcr:con[t]ent",
+                "jc[t]r:content",
+                "con[t]ent",
+
+                "jcr:con]ent",
+                "jc]r:content",
+                "con]ent",
+
+                "jcr:con[ent",
+                "jc[r:content",
+                "con[ent",
+
+                "jcr:con*ent",
+                "jc*r:content",
+                "con*ent",
+
+                "jcr:con|ent",
+                "jc|r:content",
+                "con|ent");
 
-        RepositoryException exception = null;
-        try {
-            session.itemExists("/jcr:cont]ent");
-        } catch (RepositoryException e) {
-            exception = e;
+        Session session = getAdminSession();
+        for (String name : invalid) {
+            try {
+                session.getRootNode().addNode(name);
+                fail("Invalid name " + name);
+            } catch (RepositoryException e) {
+                // success
+            } finally {
+                session.refresh(false);
+            }
         }
 
         session.setNamespacePrefix("foo", "http://foo.bar");
-        try {
-            session.itemExists("/jcr:cont]ent");
-            assertNull(exception);
-        } catch (RepositoryException e) {
-            assertNotNull(exception);
+        for (String name : invalid) {
+            try {
+                session.getRootNode().addNode(name);
+                fail("Invalid name " + name);
+            } catch (RepositoryException e) {
+                // success
+            }
         }
     }
 



Mime
View raw message