Author: rombert
Date: Mon Oct 13 11:34:37 2014
New Revision: 1631351

URL: http://svn.apache.org/r1631351
Log:
SLING-4041 - Escaped braces at the start of a property value are not
unescaped

Added:
    
sling/trunk/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/escaped-braces-at-start-of-property.xml
Modified:
    
sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java
    
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java

Modified: 
sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java?rev=1631351&r1=1631350&r2=1631351&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java
 (original)
+++ 
sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java
 Mon Oct 13 11:34:37 2014
@@ -179,6 +179,15 @@ public class ContentXmlHandlerTest {
         assertThat("root has 1 property, binary property is ignored", 
root.getProperties().entrySet(), hasSize(1));
     }
 
+    @Test
+    public void escapedBraceAtStartOfPropertyValue() throws Exception {
+
+        ResourceProxy root = 
parseContentXmlFile("escaped-braces-at-start-of-property.xml", "/");
+        assertThat("properties[org.apache.sling.commons.log.pattern]",
+                root.getProperties(), 
hasEntry("org.apache.sling.commons.log.pattern",
+                        (Object) "{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] 
{3} {5}"));
+    }
+
     private static Matcher<Calendar> millis(long millis) {
 
         return new CalendarTimeInMillisMatcher(millis);

Added: 
sling/trunk/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/escaped-braces-at-start-of-property.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/escaped-braces-at-start-of-property.xml?rev=1631351&view=auto
==============================================================================
--- 
sling/trunk/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/escaped-braces-at-start-of-property.xml
 (added)
+++ 
sling/trunk/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/escaped-braces-at-start-of-property.xml
 Mon Oct 13 11:34:37 2014
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or
+    more contributor license agreements. See the NOTICE file
+    distributed with this work for additional information regarding
+    copyright ownership. The ASF licenses this file to you under the
+    Apache License, Version 2.0 (the "License"); you may not use
+    this file except in compliance with the License. You may obtain
+    a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+    applicable law or agreed to in writing, software distributed
+    under the License is distributed on an "AS IS" BASIS, WITHOUT
+    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions
+    and limitations under the License.
+-->
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"; 
xmlns:jcr="http://www.jcp.org/jcr/1.0";
+    jcr:primaryType="sling:OsgiConfig"
+    org.apache.sling.commons.log.file="logs/missing.log"
+    org.apache.sling.commons.log.level="info"
+    org.apache.sling.commons.log.names="[org.apache.sling.missing]"
+    org.apache.sling.commons.log.pattern="\{0,date,dd.MM.yyyy HH:mm:ss.SSS} 
*{4}* [{2}] {3} {5}"/>

Modified: 
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java?rev=1631351&r1=1631350&r2=1631351&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java
 (original)
+++ 
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java
 Mon Oct 13 11:34:37 2014
@@ -239,7 +239,9 @@ public class ContentXmlHandler extends D
                 values = new String[] { rawValue };
             }
 
+            // no hint -> string type
             if (hintEnd == -1) {
+                unescape(values);
                 if (values.length == 1 && !explicitMultiValue) {
                     return values[0];
                 }
@@ -257,6 +259,15 @@ public class ContentXmlHandler extends D
             throw new IllegalArgumentException("Unknown typeHint value '" + 
rawHint + "'");
         }
 
+        private static void unescape(String[] values) {
+
+            for (int i = 0; i < values.length; i++) {
+                if (values[i].length() > 0 && values[i].charAt(0) == '\\') {
+                    values[i] = values[i].substring(1);
+                }
+            }
+        }
+
         private final String rawHint;
 
         private TypeHint(String rawHint) {


Reply via email to