mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 08:24:13 +00:00
Merge branch '7.0.x'
This commit is contained in:
@@ -917,6 +917,14 @@ public abstract class DataBufferUtils {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -153,6 +153,30 @@ class StringDecoderTests extends AbstractDecoderTests<StringDecoder> {
|
||||
.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(
|
||||
|
||||
+42
@@ -1323,6 +1323,48 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user