Skip to content

Commit 8f0a956

Browse files
committed
[bugfix] allow empty options map in map:merge#2
fixes #4620 Check for existence of "duplicates" option first. Add test to ensure map:merge#2 with empty options behaves as map:merge#1.
1 parent aec5cca commit 8f0a956

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

exist-core/src/main/java/org/exist/xquery/functions/map/MapFunction.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ private Sequence merge(final Sequence[] args) throws XPathException {
250250

251251
final MergeDuplicates mergeDuplicates;
252252
if (args.length == 2) {
253-
final Sequence mapValue = ((MapType) args[1]).get(new StringValue(this, "duplicates"));
254-
if (mapValue != null) {
253+
final MapType map = (MapType) args[1];
254+
final StringValue key = new StringValue(this, "duplicates");
255+
if (map.contains(key)) {
256+
final Sequence mapValue = map.get(key);
255257
mergeDuplicates = MergeDuplicates.fromDuplicatesValue(mapValue.getStringValue());
256258
if (mergeDuplicates == null) {
257259
throw new XPathException(this, ErrorCodes.FOJS0005, "value for duplicates key was not recognised: " + mapValue.getStringValue());

exist-core/src/test/xquery/maps/maps.xqm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,3 +976,16 @@ function mt:immutable-merge-duplicates-then-merge() {
976976
$expected ne $result($mt:test-key-one)
977977
)
978978
};
979+
980+
(:~
981+
: ensure that empty options map is allowed and behaves like
982+
: map:merge#1
983+
:)
984+
declare
985+
%test:assertTrue
986+
function mt:map-merge-2-empty-options-map() {
987+
let $maps := (mt:getMapFixture(), map { "Su": "Sunnuntai" })
988+
let $expected := map:merge($maps)
989+
let $actual := map:merge($maps, map {})
990+
return $expected?Su eq $actual?Su
991+
};

0 commit comments

Comments
 (0)