Skip to content

Commit

Permalink
assert charset is utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mkubik committed Nov 19, 2024
1 parent 2f0032c commit 67e001b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.snowflake.client.core.arrow;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -45,7 +46,7 @@ public Object toObject(int index) throws SFException {

@Override
public byte[] toBytes(int index) throws SFException {
return isNull(index) ? null : toString(index).getBytes();
return isNull(index) ? null : toString(index).getBytes(StandardCharsets.UTF_8);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.snowflake.client.core.json;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.Types;
import net.snowflake.client.core.SFException;
Expand Down Expand Up @@ -53,7 +54,7 @@ public byte[] getBytes(Object obj, int columnType, int columnSubType, Integer sc
return converters
.getStringConverter()
.getString(obj, columnType, columnSubType, scale)
.getBytes(StandardCharsets.UTF_8);
.getBytes();
case Types.BOOLEAN:
return converters.getBooleanConverter().getBoolean(obj, columnType)
? new byte[] {1}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.snowflake.client.jdbc.structuredtypes;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -66,6 +69,7 @@ protected void assertGetObjectIsCompatible(ResultSet resultSet, String expected)

protected void assertGetBytesIsCompatible(ResultSet resultSet, String expected)
throws SQLException {
assertEquals(StandardCharsets.UTF_8, Charset.defaultCharset());
TestUtil.assertEqualsIgnoringWhitespace(
expected, new String(resultSet.getBytes(1)));
}
Expand Down

0 comments on commit 67e001b

Please sign in to comment.