Skip to content

Commit

Permalink
Fix TestKit encoding where ByteBuffer.array may not exactly repre…
Browse files Browse the repository at this point in the history
…sent 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 <[email protected]>

[resolves #264]

Signed-off-by: Mark Paluch <[email protected]>
  • Loading branch information
diego Dupin authored and mp911de committed Feb 3, 2022
1 parent 8ba4a7c commit 80b6ece
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions r2dbc-spi-test/src/main/java/io/r2dbc/spi/test/TestKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

});
Expand All @@ -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();
Expand All @@ -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();
}
Expand Down

0 comments on commit 80b6ece

Please sign in to comment.