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 @@ -694,7 +694,16 @@ public void writeString(String s) {
} else if (c < 0x80) {
writeByte((byte) c);
} else {
byte[] utf8 = String.valueOf(c).getBytes(StandardCharsets.UTF_8);
String chunk;
if (Character.isHighSurrogate(c)
&& i + 1 < len
&& Character.isLowSurrogate(s.charAt(i + 1))) {
chunk = s.substring(i, i + 2);
i++;
} else {
chunk = String.valueOf(c);
}
byte[] utf8 = chunk.getBytes(StandardCharsets.UTF_8);
ensureCapacity(count + utf8.length);
System.arraycopy(utf8, 0, buf, count, utf8.length);
count += utf8.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ void testSerializePipelineRequestOneShot() throws IOException {
assertThat(json).contains("\"value\":\"hello \\\"world\\\"\\nnewline\"");
}

@Test
void testSerializeSupplementaryCharactersAsUtf8() throws IOException {
String supplementary = "\uD840\uDC40 and \uD880\uDC99";
Stmt stmt = new Stmt("SELECT '" + supplementary + "'", List.of(Value.of(supplementary)));
PipelineReqBody req = new PipelineReqBody(null, List.of(new StreamRequest.Execute(stmt)));

byte[] jsonBytes = codec.serializePipelineRequest(req);
String json = new String(jsonBytes, StandardCharsets.UTF_8);

assertThat(json).contains("\"sql\":\"SELECT '" + supplementary + "'\"");
assertThat(json).contains("\"value\":\"" + supplementary + "\"");
assertThat(json).doesNotContain("?");
}

@Test
void testDeserializePipelineResponse() throws IOException {
String json = """
Expand Down
Loading
Loading