jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1519105 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
Date Fri, 30 Aug 2013 22:49:36 GMT
Author: tripod
Date: Fri Aug 30 22:49:36 2013
New Revision: 1519105

URL: http://svn.apache.org/r1519105
Log:
JCR-3661 jcrvlt: String[]{""} not packaged correctly

Modified:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java?rev=1519105&r1=1519104&r2=1519105&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
Fri Aug 30 22:49:36 2013
@@ -174,6 +174,12 @@ public class DocViewProperty {
                         state = 'u';
                         unicode = 0;
                         unicodePos = 0;
+                    } else if (c == '0') {
+                        // special case to treat empty values. see JCR-3661
+                        state = 'v';
+                        if (vals == null) {
+                            vals = new LinkedList<String>();
+                        }
                     } else {
                         state = 'v';
                         tmp.append(c);
@@ -247,14 +253,19 @@ public class DocViewProperty {
                         attrValue.append(',');
                     }
                     String strValue = ValueHelper.serialize(values[i], false);
-                    switch (prop.getType()) {
-                        case PropertyType.STRING:
-                        case PropertyType.NAME:
-                        case PropertyType.PATH:
-                            escape(attrValue, strValue, true);
-                            break;
-                        default:
-                            attrValue.append(strValue);
+                    if (values.length == 1 && strValue.length() == 0) {
+                        // special case for empty string MV value (JCR-3661)
+                        attrValue.append("\\0");
+                    } else {
+                        switch (prop.getType()) {
+                            case PropertyType.STRING:
+                            case PropertyType.NAME:
+                            case PropertyType.PATH:
+                                escape(attrValue, strValue, true);
+                                break;
+                            default:
+                                attrValue.append(strValue);
+                        }
                     }
                 }
                 attrValue.append(']');

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java?rev=1519105&r1=1519104&r2=1519105&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
Fri Aug 30 22:49:36 2013
@@ -17,9 +17,13 @@
 
 package org.apache.jackrabbit.vault.util;
 
+import javax.jcr.Property;
 import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.nodetype.PropertyDefinition;
 
 import org.apache.jackrabbit.util.Text;
+import org.mockito.Mockito;
 
 import junit.framework.TestCase;
 
@@ -112,6 +116,54 @@ public class DocViewPropertyTest extends
         assertEquals(p, true, PropertyType.UNDEFINED);
     }
 
+    /**
+     * Special test for mv properties with 1 empty string value (JCR-3661)
+     * @throws Exception
+     */
+    public void testEmptyMVString() throws Exception {
+        Property p = Mockito.mock(Property.class);
+        Value value = Mockito.mock(Value.class);
+
+        Mockito.when(value.getString()).thenReturn("");
+        Value[] values = new Value[]{value};
+        PropertyDefinition pd = Mockito.mock(PropertyDefinition.class);
+        Mockito.when(pd.isMultiple()).thenReturn(true);
+
+        Mockito.when(p.getType()).thenReturn(PropertyType.STRING);
+        Mockito.when(p.getName()).thenReturn("foo");
+        Mockito.when(p.getValues()).thenReturn(values);
+        Mockito.when(p.getDefinition()).thenReturn(pd);
+
+        String result = DocViewProperty.format(p);
+        assertEquals("formatted property", "[\\0]", result);
+
+        // now round trip back
+        DocViewProperty dp = DocViewProperty.parse("foo", result);
+        assertEquals(dp, true, PropertyType.UNDEFINED, "");
+    }
+
+    public void testEmptyMVBoolean() throws Exception {
+        Property p = Mockito.mock(Property.class);
+        Value value = Mockito.mock(Value.class);
+
+        Mockito.when(value.getString()).thenReturn("false");
+        Value[] values = new Value[]{value};
+        PropertyDefinition pd = Mockito.mock(PropertyDefinition.class);
+        Mockito.when(pd.isMultiple()).thenReturn(true);
+
+        Mockito.when(p.getType()).thenReturn(PropertyType.BOOLEAN);
+        Mockito.when(p.getName()).thenReturn("foo");
+        Mockito.when(p.getValues()).thenReturn(values);
+        Mockito.when(p.getDefinition()).thenReturn(pd);
+
+        String result = DocViewProperty.format(p);
+        assertEquals("formatted property", "{Boolean}[false]", result);
+
+        // now round trip back
+        DocViewProperty dp = DocViewProperty.parse("foo", result);
+        assertEquals(dp, true, PropertyType.BOOLEAN, "false");
+    }
+
     public void testEscape() {
         assertEscaped("hello", "hello", false);
         assertEscaped("hello, world", "hello, world", false);



Mime
View raw message