mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Fix "remove" implementation in netty headers adapter
Prior to this commit, the `Netty4HeadersAdapter` `MultiValueMapi#remove` implementation would return an empty list if no value was present. This is not consistent with other implementations. This change ensures that `null` is returned for those cases. Fixes gh-36226
This commit is contained in:
+1
-1
@@ -129,7 +129,7 @@ class UndertowHeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
@Nullable
|
||||
public List<String> remove(Object key) {
|
||||
if (key instanceof String headerName) {
|
||||
if (key instanceof String headerName && this.headers.contains(headerName)) {
|
||||
Collection<String> removed = this.headers.remove(headerName);
|
||||
if (removed != null) {
|
||||
return new ArrayList<>(removed);
|
||||
|
||||
@@ -144,7 +144,7 @@ public final class Netty4HeadersAdapter implements MultiValueMap<String, String>
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> remove(Object key) {
|
||||
if (key instanceof String headerName) {
|
||||
if (key instanceof String headerName && this.headers.contains(headerName)) {
|
||||
List<String> previousValues = this.headers.getAll(headerName);
|
||||
this.headers.remove(headerName);
|
||||
return previousValues;
|
||||
|
||||
+13
@@ -85,6 +85,19 @@ class HeadersAdaptersTests {
|
||||
.hasSize(0);
|
||||
}
|
||||
|
||||
@ParameterizedHeadersTest
|
||||
void shouldReturnNullWhenRemoveUnknown(MultiValueMap<String, String> headers) {
|
||||
assertThat(headers.remove("unknown")).isEqualTo(null);
|
||||
}
|
||||
|
||||
@ParameterizedHeadersTest
|
||||
void shouldReturnPreviousValuesWhenRemove(MultiValueMap<String, String> headers) {
|
||||
headers.add("TestHeader", "first");
|
||||
headers.add("TestHEADER", "second");
|
||||
|
||||
assertThat(headers.remove("testheader")).hasSize(2);
|
||||
}
|
||||
|
||||
@ParameterizedPopulatedHeadersTest
|
||||
void toString(MultiValueMap<String, String> headers) {
|
||||
String expectedFirstHeader = "TestHeader:\"first\", \"second\", \"third\"";
|
||||
|
||||
Reference in New Issue
Block a user