Skip to content

Commit a3eb77c

Browse files
committed
[fix] flatten arrays when normalizing for serialization
1 parent 9612bd3 commit a3eb77c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/FunSerialize.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.exist.storage.serializers.EXistOutputKeys;
2929
import org.exist.util.serializer.XQuerySerializer;
3030
import org.exist.xquery.*;
31+
import org.exist.xquery.functions.array.ArrayType;
3132
import org.exist.xquery.functions.map.AbstractMapType;
3233
import org.exist.xquery.util.SerializerUtils;
3334
import org.exist.xquery.value.*;
@@ -157,6 +158,12 @@ public static Sequence normalize(final Expression callingExpr, final XQueryConte
157158
"It is an error if an item in the sequence to serialize is an attribute node or a namespace node.");
158159
}
159160
temp.add(next);
161+
} else if (itemType == Type.ARRAY) {
162+
final Sequence sequence = ArrayType.flatten(next);
163+
if (sequence.isEmpty()) {
164+
continue;
165+
}
166+
temp.add(new StringValue(callingExpr, sequence.getStringValue()));
160167
} else {
161168
// atomic value
162169
// "For each item in S1, if the item is atomic, obtain the lexical representation of the item by

exist-core/src/test/xquery/xquery3/serialize.xql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ function ser:array-with-members-serializes-to-empty-string() {
989989
};
990990

991991
declare
992-
%test:assertEquals("|")
992+
%test:assertEquals("")
993993
function ser:sequence-of-empty-arrays-serializes-to-empty-string() {
994994
serialize(([],[]), map{"item-separator": "|"})
995995
};

0 commit comments

Comments
 (0)