You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2012/07/20 12:14:49 UTC

svn commit: r1363706 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java

Author: cziegeler
Date: Fri Jul 20 10:14:48 2012
New Revision: 1363706

URL: http://svn.apache.org/viewvc?rev=1363706&view=rev
Log:
SLING-2518 : Exception thrown from jcrPropertyMap.containsKey("")

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java?rev=1363706&r1=1363705&r2=1363706&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java Fri Jul 20 10:14:48 2012
@@ -346,6 +346,11 @@ public class JcrPropertyMap
                 final Property prop = node.getProperty(key);
                 return cacheProperty(prop);
             }
+        } catch (final RepositoryException re) {
+            throw new IllegalArgumentException(re);
+        }
+
+        try {
             // for compatiblity with older versions we use the (wrong) ISO9075 path
             // encoding
             final String oldKey = ISO9075.encodePath(name);
@@ -354,7 +359,7 @@ public class JcrPropertyMap
                 return cacheProperty(prop);
             }
         } catch (final RepositoryException re) {
-            throw new IllegalArgumentException(re);
+            // we ignore this
         }
 
         // property not found
@@ -370,7 +375,8 @@ public class JcrPropertyMap
      */
     protected String escapeKeyName(final String key) throws RepositoryException {
         final int indexOfPrefix = key.indexOf(':');
-        if (indexOfPrefix != -1 && key.length() > indexOfPrefix + 1) {
+        // check if colon is neither the first nor the last character
+        if (indexOfPrefix > 0 && key.length() > indexOfPrefix + 1) {
             final String prefix = key.substring(0, indexOfPrefix);
             for (final String existingPrefix : getNode().getSession()
                     .getNamespacePrefixes()) {

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java?rev=1363706&r1=1363705&r2=1363706&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrPropertyMapTest.java Fri Jul 20 10:14:48 2012
@@ -295,6 +295,7 @@ public class JcrPropertyMapTest extends 
     private static final String PROP1 = "-prop";
     private static final String PROP2 = "1prop";
     private static final String PROP3 = "jcr:title";
+    private static final String PROP4 = ":prop";
 
     public void testNames() throws Exception {
         this.rootNode.getSession().refresh(false);
@@ -307,6 +308,16 @@ public class JcrPropertyMapTest extends 
         assertEquals(VALUE1, vm.get(PROP1));
         assertEquals(VALUE2, vm.get(PROP2));
         assertEquals(VALUE3, vm.get(PROP3));
+        vm.get(PROP4);
+    }
+
+    public void testColon() throws Exception {
+        this.rootNode.getSession().refresh(false);
+        final ValueMap vm = this.createPropertyMap(this.rootNode);
+        assertNull(vm.get(":prop"));
+        assertNull(vm.get("prop:"));
+        assertNull(vm.get("jcr:title"));
+        assertNull(vm.get("unknown:prefix"));
     }
 
     public void testIerators() throws Exception {