Skip to content

Commit 0ef3cb9

Browse files
committed
Merge branch '6.0.x'
2 parents ca96341 + 8868fe2 commit 0ef3cb9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public void toByteBuffer(int srcPos, ByteBuffer dest, int destPos, int length) {
313313
Assert.notNull(dest, "Dest must not be null");
314314

315315
dest = dest.duplicate().clear();
316-
dest.put(destPos, this.byteBuf.nioBuffer(), srcPos, length);
316+
dest.put(destPos, this.byteBuf.nioBuffer(srcPos, length), 0, length);
317317
}
318318

319319
@Override

spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,10 +796,6 @@ void slice(DataBufferFactory bufferFactory) {
796796
if (!(bufferFactory instanceof Netty5DataBufferFactory)) {
797797
assertThat(result).isEqualTo(new byte[]{'b', 'c'});
798798
}
799-
else {
800-
assertThat(result).isEqualTo(new byte[]{'b', 0});
801-
release(slice);
802-
}
803799
release(buffer);
804800
}
805801

@@ -938,4 +934,15 @@ void getByte(DataBufferFactory bufferFactory) {
938934
release(buffer);
939935
}
940936

937+
@ParameterizedDataBufferAllocatingTest // gh-31605
938+
void shouldHonorSourceBuffersReadPosition(DataBufferFactory bufferFactory) {
939+
DataBuffer dataBuffer = bufferFactory.wrap("ab".getBytes(StandardCharsets.UTF_8));
940+
dataBuffer.readPosition(1);
941+
942+
ByteBuffer byteBuffer = ByteBuffer.allocate(dataBuffer.readableByteCount());
943+
dataBuffer.toByteBuffer(byteBuffer);
944+
945+
assertThat(StandardCharsets.UTF_8.decode(byteBuffer).toString()).isEqualTo("b");
946+
}
947+
941948
}

0 commit comments

Comments
 (0)