From 80b6ece5819fbbc560ed0019be4425b2a6a72c4a Mon Sep 17 00:00:00 2001 From: diego Dupin Date: Thu, 3 Feb 2022 14:04:39 +0100 Subject: [PATCH] Fix `TestKit` encoding where `ByteBuffer.array` may not exactly represent UTF8 encoded bytes. backing array ByteBuffer.array may not exactly represent UTF8 encoded bytes. PR permit to ensure test is valid whatever the JVM is used Example using jdk8: "test-value".getBytes(StandardCharsets.UTF_8) => 0x746573742D76616C7565 StandardCharsets.UTF_8.encode("test-value").array() => 0x746573742D76616C756500 having an additional ending 0x00 Signed-off-by: diego Dupin [resolves #264] Signed-off-by: Mark Paluch --- CHANGELOG | 1 + r2dbc-spi-test/src/main/java/io/r2dbc/spi/test/TestKit.java | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a0aeb74..7127ce4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ R2DBC SPI Changelog 0.9.1.RELEASE ------------------ +* Fix `TestKit` encoding where `ByteBuffer.array` may not exactly represent UTF8 encoded bytes #264 * `DefaultParameter` does not implement `equals` and `hashCode` methods #260 0.9.0.RELEASE diff --git a/r2dbc-spi-test/src/main/java/io/r2dbc/spi/test/TestKit.java b/r2dbc-spi-test/src/main/java/io/r2dbc/spi/test/TestKit.java index 410deaa..462e592 100644 --- a/r2dbc-spi-test/src/main/java/io/r2dbc/spi/test/TestKit.java +++ b/r2dbc-spi-test/src/main/java/io/r2dbc/spi/test/TestKit.java @@ -379,7 +379,7 @@ default void blobSelect() { @Override protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { - lobCreator.setBlobAsBytes(ps, 1, StandardCharsets.UTF_8.encode("test-value").array()); + lobCreator.setBlobAsBytes(ps, 1, "test-value".getBytes(StandardCharsets.UTF_8)); } }); @@ -401,7 +401,7 @@ protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQL Connection::close) .as(StepVerifier::create) .expectNextMatches(actual -> { - ByteBuffer expected = StandardCharsets.UTF_8.encode("test-value"); + ByteBuffer expected = ByteBuffer.wrap("test-value".getBytes(StandardCharsets.UTF_8)); return Arrays.equals(expected.array(), actual); }) .verifyComplete(); @@ -420,7 +420,7 @@ protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQL .as(StepVerifier::create) .expectNextMatches(actual -> { ByteBuffer expected = StandardCharsets.UTF_8.encode("test-value"); - return Arrays.equals(expected.array(), actual.array()); + return actual.compareTo(expected) == 0; }) .verifyComplete(); }