Skip to content

Commit b4699fe

Browse files
committed
[bugfix] Significant characters within a picture string for a Decimal Format must be distinct
1 parent 11a5419 commit b4699fe

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

exist-core/src/main/antlr/org/exist/xquery/parser/XQueryTree.g

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ throws PermissionDeniedException, EXistException, XPathException
556556
}
557557

558558
final DecimalFormat df = DecimalFormat.fromProperties(dfProperties);
559+
if (!df.checkDistinctCharacters()) {
560+
throw new XPathException(dfName.getLine(), dfName.getColumn(), ErrorCodes.W3CErrorCode.XQST0098.getErrorCode(), "Characters within the picture string of the decimal format: " + dfName.getText() + " are not distinct.");
561+
}
562+
559563
staticContext.setStaticDecimalFormat(qnDfName, df);
560564
context.setStaticDecimalFormat(qnDfName, df);
561565
}

exist-core/src/main/java/org/exist/xquery/DecimalFormat.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ public DecimalFormat(final int decimalSeparator, final int exponentSeparator, fi
106106
this.minusSign = minusSign;
107107
}
108108

109+
/**
110+
* Checks that the characters used in a picture string have distinct values.
111+
*
112+
* @return true if all the characters are distinct, false otherwise.
113+
*/
114+
public boolean checkDistinctCharacters() {
115+
final int[] characters = new int[] {
116+
decimalSeparator,
117+
exponentSeparator,
118+
groupingSeparator,
119+
percent,
120+
perMille,
121+
zeroDigit,
122+
digit,
123+
patternSeparator
124+
};
125+
126+
for (int i = 0; i < characters.length; i++) {
127+
final int c = characters[i];
128+
for (int j = i + 1; j < characters.length; j++) {
129+
final int o = characters[j];
130+
if (c == o) {
131+
return false;
132+
}
133+
}
134+
}
135+
136+
return true;
137+
}
138+
109139
public static DecimalFormat fromProperties(final Map<String, String> properties) {
110140
int decimalSeparator = UNNAMED.decimalSeparator;
111141
int exponentSeparator = UNNAMED.exponentSeparator;

exist-core/src/main/java/org/exist/xquery/ErrorCodes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public enum W3CErrorCode implements IErrorCode {
220220
XQDY0092 ("An implementation MAY raise a dynamic error if a constructed attribute named xml:space has a value other than preserve or default."),
221221
XQST0093 ("It is a static error to import a module M1 if there exists a sequence of modules M1 ... Mi ... M1 such that each module directly depends on the next module in the sequence (informally, if M1 depends on itself through some chain of module dependencies.)"),
222222
XQST0094 ("The name of each grouping variable must be equal (by the eq operator on expanded QNames) to the name of a variable in the input tuple stream."),
223+
XQST0098 ("It is a static error if, for any named or unnamed decimal format, the properties representing characters used in a picture string do not each have distinct values. The following properties represent characters used in a picture string: decimal-separator, exponent-separator, grouping-separator, percent, per-mille, the family of ten decimal digits starting with zero-digit, digit, and pattern-separator."),
223224
XQDY0101 ("An error is raised if a computed namespace constructor attempts to do any of the following: Bind the prefix xml to some namespace URI other than http://www.w3.org/XML/1998/namespace. Bind a prefix other than xml to the namespace URI http://www.w3.org/XML/1998/namespace. Bind the prefix xmlns to any namespace URI. Bind a prefix to the namespace URI http://www.w3.org/2000/xmlns/. Bind any prefix (including the empty prefix) to a zero-length namespace URI."),
224225
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."),
225226
XQST0103 ("All variables in a window clause must have distinct names."),

0 commit comments

Comments
 (0)