|
19 | 19 | import static io.rsocket.metadata.CompositeMetadataFlyweight.decodeMimeAndContentBuffersSlices;
|
20 | 20 | import static io.rsocket.metadata.CompositeMetadataFlyweight.decodeMimeIdFromMimeBuffer;
|
21 | 21 | import static io.rsocket.metadata.CompositeMetadataFlyweight.decodeMimeTypeFromMimeBuffer;
|
22 |
| -import static org.assertj.core.api.Assertions.assertThat; |
23 |
| -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; |
24 |
| -import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
25 |
| - |
26 |
| -import io.netty.buffer.ByteBuf; |
27 |
| -import io.netty.buffer.ByteBufAllocator; |
28 |
| -import io.netty.buffer.CompositeByteBuf; |
29 |
| -import io.netty.buffer.Unpooled; |
30 |
| -import io.netty.buffer.UnpooledByteBufAllocator; |
| 22 | +import static org.assertj.core.api.Assertions.*; |
| 23 | + |
| 24 | +import io.netty.buffer.*; |
31 | 25 | import io.netty.util.CharsetUtil;
|
32 | 26 | import io.rsocket.test.util.ByteBufUtils;
|
33 | 27 | import io.rsocket.util.NumberUtils;
|
@@ -524,4 +518,37 @@ void knownMimeHeaderZero_avro() {
|
524 | 518 |
|
525 | 519 | assertThat(content.readableBytes()).as("no metadata content").isZero();
|
526 | 520 | }
|
| 521 | + |
| 522 | + @Test |
| 523 | + void encodeCustomHeaderAsciiCheckSkipsFirstByte() { |
| 524 | + final ByteBuf badBuf = Unpooled.copiedBuffer("é00000000000", CharsetUtil.UTF_8); |
| 525 | + badBuf.writerIndex(0); |
| 526 | + assertThat(badBuf.readerIndex()).isZero(); |
| 527 | + |
| 528 | + ByteBufAllocator allocator = |
| 529 | + new AbstractByteBufAllocator() { |
| 530 | + @Override |
| 531 | + public boolean isDirectBufferPooled() { |
| 532 | + return false; |
| 533 | + } |
| 534 | + |
| 535 | + @Override |
| 536 | + protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity) { |
| 537 | + return badBuf; |
| 538 | + } |
| 539 | + |
| 540 | + @Override |
| 541 | + protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity) { |
| 542 | + return badBuf; |
| 543 | + } |
| 544 | + }; |
| 545 | + |
| 546 | + assertThatCode( |
| 547 | + () -> CompositeMetadataFlyweight.encodeMetadataHeader(allocator, "custom/type", 0)) |
| 548 | + .doesNotThrowAnyException(); |
| 549 | + |
| 550 | + assertThat(badBuf.readByte()).isEqualTo((byte) 10); |
| 551 | + assertThat(badBuf.readCharSequence(11, CharsetUtil.UTF_8)).hasToString("custom/type"); |
| 552 | + assertThat(badBuf.readUnsignedMedium()).isEqualTo(0); |
| 553 | + } |
527 | 554 | }
|
0 commit comments