Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DA7C3915A for ; Fri, 15 Jun 2012 16:37:23 +0000 (UTC) Received: (qmail 45612 invoked by uid 500); 15 Jun 2012 16:37:23 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 45575 invoked by uid 500); 15 Jun 2012 16:37:23 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 45564 invoked by uid 99); 15 Jun 2012 16:37:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Jun 2012 16:37:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Jun 2012 16:37:22 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 035492388BEF; Fri, 15 Jun 2012 16:37:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1350684 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/ test/java/org/apache/sling/jcr/resource/internal/ Date: Fri, 15 Jun 2012 16:37:01 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120615163702.035492388BEF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Fri Jun 15 16:37:01 2012 New Revision: 1350684 URL: http://svn.apache.org/viewvc?rev=1350684&view=rev Log: SLING-2502 : Incorrect escaping of property names in JcrModifiablePropertyMap on save. Applied patch from Alex Parvulescu Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java 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/JcrModifiablePropertyMapTest.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/JcrModifiablePropertyMap.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java?rev=1350684&r1=1350683&r2=1350684&view=diff ============================================================================== --- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java (original) +++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java Fri Jun 15 16:37:01 2012 @@ -196,7 +196,7 @@ public final class JcrModifiableProperty } for(final String key : this.changedProperties) { - final String name = Text.escapeIllegalJcrChars(key); + final String name = escapeKeyName(key); if ( !MIXIN_TYPES.equals(name) ) { if ( cache.containsKey(key) ) { final JcrPropertyMapCacheEntry entry = cache.get(key); 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=1350684&r1=1350683&r2=1350684&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 Jun 15 16:37:01 2012 @@ -336,8 +336,8 @@ public class JcrPropertyMap return cache.get(name); } - final String key = Text.escapeIllegalJcrChars(name); try { + final String key = escapeKeyName(name); if (node.hasProperty(key)) { final Property prop = node.getProperty(key); return cacheProperty(prop); @@ -358,6 +358,30 @@ public class JcrPropertyMap } /** + * Handles key name escaping by taking into consideration if it contains a + * registered prefix + * + * @param key + * @return escaped key name + */ + protected String escapeKeyName(final String key) throws RepositoryException { + final int indexOfPrefix = key.indexOf(':'); + if (indexOfPrefix != -1 && key.length() > indexOfPrefix + 1) { + final String prefix = key.substring(0, indexOfPrefix); + for (final String existingPrefix : getNode().getSession() + .getNamespacePrefixes()) { + if (existingPrefix.equals(prefix)) { + return prefix + + ":" + + Text.escapeIllegalJcrChars(key + .substring(indexOfPrefix + 1)); + } + } + } + return Text.escapeIllegalJcrChars(key); + } + + /** * Read all properties. * @throws IllegalArgumentException if a repository exception occurs */ Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java?rev=1350684&r1=1350683&r2=1350684&view=diff ============================================================================== --- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java (original) +++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java Fri Jun 15 16:37:01 2012 @@ -18,7 +18,6 @@ */ package org.apache.sling.jcr.resource.internal; -import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; @@ -31,6 +30,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.nodetype.NodeType; +import org.apache.jackrabbit.util.Text; import org.apache.sling.api.resource.PersistableValueMap; import org.apache.sling.api.resource.ValueMap; import org.apache.sling.jcr.resource.JcrModifiablePropertyMap; @@ -77,7 +77,8 @@ public class JcrModifiablePropertyMapTes } public void testPut() - throws IOException { + throws Exception { + this.rootNode.getSession().refresh(false); final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode); assertContains(pvm, initialSet()); assertNull(pvm.get("something")); @@ -99,7 +100,8 @@ public class JcrModifiablePropertyMapTes } public void testReset() - throws IOException { + throws Exception { + this.rootNode.getSession().refresh(false); final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode); assertContains(pvm, initialSet()); assertNull(pvm.get("something")); @@ -121,7 +123,8 @@ public class JcrModifiablePropertyMapTes } public void testSerializable() - throws IOException { + throws Exception { + this.rootNode.getSession().refresh(false); final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode); assertContains(pvm, initialSet()); assertNull(pvm.get("something")); @@ -147,7 +150,8 @@ public class JcrModifiablePropertyMapTes } - public void testExceptions() { + public void testExceptions() throws Exception { + this.rootNode.getSession().refresh(false); final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode); try { pvm.put(null, "something"); @@ -172,6 +176,7 @@ public class JcrModifiablePropertyMapTes } public void testMixins() throws Exception { + this.rootNode.getSession().refresh(false); final Node testNode = this.rootNode.addNode("testMixins" + System.currentTimeMillis()); testNode.getSession().save(); final PersistableValueMap pvm = new JcrModifiablePropertyMap(testNode); @@ -197,6 +202,73 @@ public class JcrModifiablePropertyMapTes assertEquals(newNodeTypes.size(), exNodeTypes.size() + 1); } + private static final String TEST_PATH = "a