Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,17 @@ public static Slice varcharToCharSaturatedFloorCast(@LiteralParameter("y") long
return Slices.allocate(toIntExact(y));
}

codePoints.set(codePoints.size() - 1, codePoints.get(codePoints.size() - 1) - 1);
int lastCodePoint = codePoints.get(codePoints.size() - 1) - 1;
/*
* UTF-8 reserve codepoints from 0xD800 to 0xDFFF for encoding UTF-16
Comment thread
martint marked this conversation as resolved.
Outdated
* If the lastCodePoint after -1 operation is in this range, it will lead to an InvalidCodePointException
* Since the codePoint is originally valid, so the only case will be 0XE00 - 1
* So we let it go through this range and become 0xD7FF
*/
if (lastCodePoint == Character.MAX_SURROGATE) {
lastCodePoint = Character.MIN_SURROGATE - 1;
}
codePoints.set(codePoints.size() - 1, lastCodePoint);
int toAdd = toIntExact(y) - codePoints.size();
for (int i = 0; i < toAdd; i++) {
codePoints.add(Character.MAX_CODE_POINT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public void testVarcharToCharSaturatedFloorCast()
String maxCodePoint = new String(Character.toChars(Character.MAX_CODE_POINT));
String codePointBeforeSpace = new String(Character.toChars(' ' - 1));

assertEquals(varcharToCharSaturatedFloorCast(
5L,
utf8Slice("123" + new String(Character.toChars(0xE000)))),
utf8Slice("123" + new String(Character.toChars(0xD7FF)) + maxCodePoint));

// Truncation
assertEquals(varcharToCharSaturatedFloorCast(
4L,
Expand Down