Skip to content

Commit 7bcff61

Browse files
committed
[bugfix] Only remove the decimal separator in fn:format-number if there is no decimal separator in the picture, or there are no fractional digits, and the decimal separator is the right-most character
1 parent 8f93c8d commit 7bcff61

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

exist-core/src/main/java/org/exist/util/CodePointString.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,14 @@ public CodePointString insert(final int[] indexes, final int codePoint) {
353353
* @return this
354354
*/
355355
public CodePointString removeFirst(final int codePoint) {
356-
int idx = -1;
357-
for (int i = 0; i < codePoints.length; i++) {
358-
if (codePoints[i] == codePoint) {
359-
idx = i;
360-
break;
361-
}
362-
}
356+
final int idx = indexOf(codePoint);
357+
return removeChar(idx);
358+
}
363359

360+
/**
361+
* Removes the codepoint at the specified index.
362+
*/
363+
public CodePointString removeChar(final int idx) {
364364
if (idx > -1) {
365365
final int[] newCodePoints = new int[codePoints.length - 1];
366366

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,12 @@ private String format(final NumericValue number, final DecimalFormat decimalForm
752752

753753
// Rule 12 - strip decimal separator if unneeded
754754
if (!subPicture.hasDecimalSeparator() || fractLen == 0) {
755-
formatted.removeFirst(decimalFormat.decimalSeparator);
755+
// decimal separator must be the rightmost character in the string
756+
final int rightMostIndex = formatted.length() - 1;
757+
final int rightMost = formatted.codePointAt(rightMostIndex);
758+
if (rightMost == decimalFormat.decimalSeparator) {
759+
formatted.removeChar(rightMostIndex);
760+
}
756761
}
757762

758763
// Rule 13 - add exponent if exists

0 commit comments

Comments
 (0)