Skip to content

Commit 59d4250

Browse files
committed
.getBytes(UTF_8) when passing to converter, and add UTF-8 roundtrip test
1 parent e1a6d99 commit 59d4250

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/main/java/com/github/pgasync/impl/conversion/ArrayConversions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected static Object[] buildArray(
5656
if (1 < dimensionCount) {
5757
o = buildArray(elementType, (PgArrayList) o, 0, -1, parse);
5858
} else {
59-
o = parse.apply(((String) o).getBytes());
59+
o = parse.apply(((String) o).getBytes(UTF_8));
6060
}
6161
}
6262
ret[length] = o;

src/test/java/com/github/pgasync/impl/ArrayConversionsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ public void roundtripInt() {
138138
Arrays.asList(new Object[]{a})).row(0).getArray("INTA", Integer[].class));
139139
}
140140

141+
@Test
142+
public void roundtripUTF8() {
143+
String[] a = new String[]{"U&\"d\\0061t\\+000061\"", "d\u0061t\u0061\u2301" };
144+
dbr.query("INSERT INTO CA_TEST (TEXTA) VALUES ($1)", Arrays.asList(new Object[]{a}));
145+
assertArrayEquals(
146+
a,
147+
dbr.query(
148+
"SELECT TEXTA FROM CA_TEST WHERE TEXTA = $1",
149+
Arrays.asList(new Object[]{a})).row(0).getArray("TEXTA", String[].class));
150+
}
151+
141152
@Test
142153
public void insertUnboxed() {
143154
short[][] a = new short[][]{new short[]{0, 1}, new short[]{1, 0}};

0 commit comments

Comments
 (0)