Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,14 @@ protected TwoByteMatcher(byte[] delimiter) {
super(delimiter);
Assert.isTrue(delimiter.length == 2, "Expected a 2-byte delimiter");
}

@Override
public boolean match(byte b) {
if (getMatches() > 0 && b != delimiter()[getMatches()]) {
setMatches(0);
}
return super.match(b);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ void decodeNewlinesAcrossBuffers() {
.verify());
}

@Test
void decodePreservesCharacterBeforeLoneNewlineAfterCarriageReturn() {
Flux<DataBuffer> input = Flux.just(stringBuffer("a\rXY\nb"));

testDecode(input, String.class, step -> step
.expectNext("a\rXY")
.expectNext("b")
.expectComplete()
.verify());
}

@Test
void decodePreservesCharacterAcrossBuffersAfterCarriageReturn() {
Flux<DataBuffer> input = Flux.just(
stringBuffer("a\r"),
stringBuffer("Xb\n")
);

testDecode(input, String.class, step -> step
.expectNext("a\rXb")
.expectComplete()
.verify());
}

@Test
void maxInMemoryLimit() {
Flux<DataBuffer> input = Flux.just(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,48 @@ void matcher3(DataBufferFactory bufferFactory) {
release(foo);
}

@ParameterizedDataBufferAllocatingTest
void matcherDoesNotMatchAcrossNonContiguousDelimiterBytes(DataBufferFactory bufferFactory) {
super.bufferFactory = bufferFactory;

DataBuffer buffer = stringBuffer("a\rXY\nb");

byte[] delims = "\r\n".getBytes(StandardCharsets.UTF_8);
DataBufferUtils.Matcher matcher = DataBufferUtils.matcher(delims);
int result = matcher.match(buffer);
assertThat(result).isEqualTo(-1);

release(buffer);
}

@ParameterizedDataBufferAllocatingTest
void matcherMatchesContiguousTwoByteDelimiter(DataBufferFactory bufferFactory) {
super.bufferFactory = bufferFactory;

DataBuffer buffer = stringBuffer("a\r\nb");

byte[] delims = "\r\n".getBytes(StandardCharsets.UTF_8);
DataBufferUtils.Matcher matcher = DataBufferUtils.matcher(delims);
int result = matcher.match(buffer);
assertThat(result).isEqualTo(2);

release(buffer);
}

@ParameterizedDataBufferAllocatingTest
void matcherDoesNotMatchAfterRepeatedFirstDelimiterByte(DataBufferFactory bufferFactory) {
super.bufferFactory = bufferFactory;

DataBuffer buffer = stringBuffer("a\r\rX\nb");

byte[] delims = "\r\n".getBytes(StandardCharsets.UTF_8);
DataBufferUtils.Matcher matcher = DataBufferUtils.matcher(delims);
int result = matcher.match(buffer);
assertThat(result).isEqualTo(-1);

release(buffer);
}

@ParameterizedDataBufferAllocatingTest
void propagateContextByteChannel(DataBufferFactory bufferFactory) throws IOException {
Path path = Paths.get(this.resource.getURI());
Expand Down