You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2022/07/04 17:11:59 UTC
[jackrabbit-filevault] 01/01: JCRVLT-628 fix serialization for property with type=undefined
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch bugfix/serialization-for-undefined-prop-type
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git
commit 6e437d69b11385b0aa76483d1f84c63beccd9407
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon Jul 4 19:11:53 2022 +0200
JCRVLT-628 fix serialization for property with type=undefined
just emit without type information
---
.../apache/jackrabbit/vault/util/DocViewProperty.java | 2 +-
.../apache/jackrabbit/vault/util/DocViewProperty2.java | 6 +++---
.../jackrabbit/vault/util/DocViewProperty2Test.java | 15 +++++++++++++++
.../jackrabbit/vault/util/DocViewPropertyTest.java | 16 ++++++++++++++++
4 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
index f77aaf2f..64325a14 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty.java
@@ -478,7 +478,7 @@ public class DocViewProperty {
* @return {@code true} if type information should be emitted, otherwise {@code false}
*/
private static boolean isAmbiguous(int type, String name) {
- return type != PropertyType.STRING && !UNAMBIGOUS.contains(name);
+ return type != PropertyType.STRING && type != PropertyType.UNDEFINED && !UNAMBIGOUS.contains(name);
}
/**
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty2.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty2.java
index 4d9fecd9..8cb2ce56 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty2.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/util/DocViewProperty2.java
@@ -497,15 +497,15 @@ public class DocViewProperty2 {
/**
* Checks if the type of the given property is ambiguous in respect to it's
- * property definition. the current implementation just checks some well
- * known properties.
+ * property definition. The current implementation just returns {@code false} for
+ * some well known property names and for type = PropertyType.STRING or PropertyType.UNDEFINED.
*
* @param type the type
* @param name the name
* @return {@code true} if type information should be emitted, otherwise {@code false}
*/
private static boolean isAmbiguous(int type, Name name) {
- return type != PropertyType.STRING && !UNAMBIGUOUS.contains(name);
+ return type != PropertyType.STRING && type != PropertyType.UNDEFINED && !UNAMBIGUOUS.contains(name);
}
/**
diff --git a/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewProperty2Test.java b/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewProperty2Test.java
index 6ca753c0..51edc3e9 100644
--- a/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewProperty2Test.java
+++ b/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewProperty2Test.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
+import java.util.Collections;
import javax.jcr.Binary;
import javax.jcr.NamespaceException;
@@ -278,6 +279,20 @@ public class DocViewProperty2Test {
assertEquals(DocViewProperty2.fromValues(nameFoo, new Value[]{ value, value }, PropertyType.BINARY, true, false, false), true, PropertyType.BINARY, false, "", "");
}
+ @Test
+ public void testFormat() {
+ DocViewProperty2 property = new DocViewProperty2(nameFoo, "value");
+ Assert.assertEquals("value", property.formatValue());
+ property = new DocViewProperty2(nameFoo, "true", PropertyType.BOOLEAN);
+ Assert.assertEquals("{Boolean}true", property.formatValue());
+ property = new DocViewProperty2(nameFoo, Arrays.asList("path1", "path2"), PropertyType.PATH);
+ Assert.assertEquals("{Path}[path1,path2]", property.formatValue());
+ property = new DocViewProperty2(nameFoo, Arrays.asList(""), PropertyType.STRING);
+ Assert.assertEquals("[\\0]", property.formatValue());
+ property = new DocViewProperty2(nameFoo, Collections.singletonList("1234"), false, PropertyType.BINARY, true);
+ Assert.assertEquals("{BinaryRef}1234", property.formatValue());
+ }
+
private void assertEscaped(String original, String expected, boolean multi) {
Assert.assertEquals(expected, DocViewProperty2.escape(original, multi));
}
diff --git a/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java b/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
index bf708ad0..a66f1ccd 100644
--- a/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
+++ b/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
@@ -21,6 +21,8 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Collections;
import javax.jcr.Binary;
import javax.jcr.Property;
@@ -249,6 +251,20 @@ public class DocViewPropertyTest {
assertEquals(DocViewProperty.fromValues("test", new Value[]{ value, value }, PropertyType.BINARY, true, false, false), true, PropertyType.BINARY, false, "", "");
}
+ @Test
+ public void testFormat() {
+ DocViewProperty property = new DocViewProperty("test", new String[] { "value"}, false, PropertyType.UNDEFINED);
+ Assert.assertEquals("value", property.formatValue());
+ property = new DocViewProperty("test", new String[] {"true"}, false, PropertyType.BOOLEAN);
+ Assert.assertEquals("{Boolean}true", property.formatValue());
+ property = new DocViewProperty("test", new String[]{"path1", "path2"}, true, PropertyType.PATH);
+ Assert.assertEquals("{Path}[path1,path2]", property.formatValue());
+ property = new DocViewProperty("test", new String[]{""}, true, PropertyType.STRING);
+ Assert.assertEquals("[\\0]", property.formatValue());
+ property = new DocViewProperty("test", new String[]{"1234"}, false, PropertyType.BINARY, true);
+ Assert.assertEquals("{BinaryRef}1234", property.formatValue());
+ }
+
private void assertEscaped(String original, String expected, boolean multi) {
Assert.assertEquals(expected, DocViewProperty.escape(original, multi));
}