StringDecoder shouldn't chop off strings randomly
Issue: SPR-16337
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ReactiveHttpInputMessage;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
/**
|
||||
* Reader that supports a stream of {@link ServerSentEvent}s and also plain
|
||||
@@ -56,7 +56,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
|
||||
|
||||
private static final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
private static final StringDecoder stringDecoder = StringDecoder.textPlainOnly(false);
|
||||
private static final StringDecoder stringDecoder = StringDecoder.textPlainOnly();
|
||||
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -188,12 +188,10 @@ abstract class AbstractCodecConfigurer implements CodecConfigurer {
|
||||
result.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
|
||||
result.add(new DecoderHttpMessageReader<>(new DataBufferDecoder()));
|
||||
result.add(new DecoderHttpMessageReader<>(new ResourceDecoder()));
|
||||
result.add(new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly(splitTextOnNewLine())));
|
||||
result.add(new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly()));
|
||||
return result;
|
||||
}
|
||||
|
||||
abstract boolean splitTextOnNewLine();
|
||||
|
||||
List<HttpMessageReader<?>> getObjectReaders() {
|
||||
if (!this.registerDefaults) {
|
||||
return Collections.emptyList();
|
||||
@@ -216,7 +214,7 @@ abstract class AbstractCodecConfigurer implements CodecConfigurer {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<HttpMessageReader<?>> result = new ArrayList<>();
|
||||
result.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(splitTextOnNewLine())));
|
||||
result.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,11 +70,6 @@ public class DefaultClientCodecConfigurer extends AbstractCodecConfigurer implem
|
||||
this.sseDecoder = decoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean splitTextOnNewLine() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
List<HttpMessageReader<?>> getObjectReaders() {
|
||||
if (!shouldRegisterDefaults()) {
|
||||
@@ -110,8 +105,7 @@ public class DefaultClientCodecConfigurer extends AbstractCodecConfigurer implem
|
||||
}
|
||||
else {
|
||||
DefaultCustomCodecs customCodecs = getCustomCodecs();
|
||||
partWriters = new ArrayList<>();
|
||||
partWriters.addAll(super.getTypedWriters());
|
||||
partWriters = new ArrayList<>(super.getTypedWriters());
|
||||
if (customCodecs != null) {
|
||||
partWriters.addAll(customCodecs.getTypedWriters());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,11 +66,6 @@ public class DefaultServerCodecConfigurer extends AbstractCodecConfigurer implem
|
||||
this.sseEncoder = encoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean splitTextOnNewLine() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
List<HttpMessageReader<?>> getTypedReaders() {
|
||||
if (!shouldRegisterDefaults()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -269,6 +269,11 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
|
||||
return this.dataBuffer.capacity(newCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getByte(int index) {
|
||||
return this.dataBuffer.getByte(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte read() {
|
||||
return this.dataBuffer.read();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.http.codec.support;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -55,10 +56,7 @@ import org.springframework.http.codec.xml.Jaxb2XmlDecoder;
|
||||
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.core.ResolvableType.forClass;
|
||||
|
||||
/**
|
||||
@@ -141,7 +139,7 @@ public class ClientCodecConfigurerTests {
|
||||
Flux.just(new DefaultDataBufferFactory().wrap("line1\nline2".getBytes(StandardCharsets.UTF_8))),
|
||||
ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN, Collections.emptyMap());
|
||||
|
||||
assertEquals(Collections.singletonList("line1\nline2"), decoded.collectList().block(Duration.ZERO));
|
||||
assertEquals(Arrays.asList("line1", "line2"), decoded.collectList().block(Duration.ZERO));
|
||||
}
|
||||
|
||||
private void assertStringEncoder(Encoder<?> encoder, boolean textOnly) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,7 +50,7 @@ import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.core.ResolvableType.*;
|
||||
import static org.springframework.core.ResolvableType.forClass;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractCodecConfigurer.AbstractDefaultCodecs}.
|
||||
@@ -292,10 +292,6 @@ public class CodecConfigurerTests {
|
||||
|
||||
private static class TestDefaultCodecs extends AbstractDefaultCodecs {
|
||||
|
||||
@Override
|
||||
boolean splitTextOnNewLine() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -59,7 +59,7 @@ import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.core.ResolvableType.*;
|
||||
import static org.springframework.core.ResolvableType.forClass;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ServerCodecConfigurer}.
|
||||
@@ -143,7 +143,7 @@ public class ServerCodecConfigurerTests {
|
||||
Flux.just(new DefaultDataBufferFactory().wrap("line1\nline2".getBytes(StandardCharsets.UTF_8))),
|
||||
ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN, Collections.emptyMap());
|
||||
|
||||
assertEquals(Arrays.asList("line1\n", "line2"), flux.collectList().block(Duration.ZERO));
|
||||
assertEquals(Arrays.asList("line1", "line2"), flux.collectList().block(Duration.ZERO));
|
||||
}
|
||||
|
||||
private void assertStringEncoder(Encoder<?> encoder, boolean textOnly) {
|
||||
|
||||
Reference in New Issue
Block a user