Skip to content

Commit 07d47c0

Browse files
committed
[bugfix] Map constructor should not allow entries with duplicate keys.
Closes #2203
1 parent be26d42 commit 07d47c0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/org/exist/xquery/ErrorCodes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ public class ErrorCodes {
131131
"Bind the prefix xmlns to any namespace URI.\n" +
132132
"Bind a prefix to the namespace URI http://www.w3.org/2000/xmlns/.\n" +
133133
"Bind any prefix (including the empty prefix) to a zero-length namespace URI.");
134-
public static final ErrorCode XQDY0138 = new W3CErrorCode("XQDY0138", "Position n does not exist in this array");
135134
public static final ErrorCode XQDY0102 = new W3CErrorCode("XQDY0102", "If the name of an element in an element constructor is in no namespace, creating a default namespace for that element using a computed namespace constructor is an error.");
135+
public static final ErrorCode XQDY0137 = new W3CErrorCode("XQDY0137", "No two keys in a map may have the same key value");
136+
public static final ErrorCode XQDY0138 = new W3CErrorCode("XQDY0138", "Position n does not exist in this array");
136137

137138
/* XQuery 1.0 and XPath 2.0 Functions and Operators http://www.w3.org/TR/xpath-functions/#error-summary */
138139
public static final ErrorCode FOER0000 = new W3CErrorCode("FOER0000", "Unidentified error.");

src/org/exist/xquery/functions/map/MapExpr.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public Sequence eval(Sequence contextSequence, final Item contextItem) throws XP
5252
}
5353
final AtomicValue atomic = key.itemAt(0).atomize();
5454
final Sequence value = mapping.value.eval(contextSequence);
55+
if (map.contains(atomic)) {
56+
throw new XPathException(this, ErrorCodes.XQDY0137, "Key \"" + atomic.getStringValue() + "\" already exists in map.");
57+
}
5558
map.add(atomic, value);
5659
}
5760
return map;

0 commit comments

Comments
 (0)