Handle null values in MockHttpServletResponse#setHeader
Prior to this commit, `MockHttpServletResponse#setHeader` would not remove the header entry when given a `null` value, as documented in the Servlet API. This commit ensures that this behavior is enforced. Fixes gh-34464
This commit is contained in:
@@ -88,6 +88,18 @@ class MockHttpServletResponseTests {
|
||||
assertThat(response.containsHeader(headerName)).isFalse();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
CONTENT_TYPE,
|
||||
CONTENT_LANGUAGE,
|
||||
"X-Test-Header"
|
||||
})
|
||||
void removeHeaderIfNullValue(String headerName) {
|
||||
response.addHeader(headerName, "test");
|
||||
response.setHeader(headerName, null);
|
||||
assertThat(response.containsHeader(headerName)).isFalse();
|
||||
}
|
||||
|
||||
@Test // gh-26493
|
||||
void setLocaleWithNullValue() {
|
||||
assertThat(response.getLocale()).isEqualTo(Locale.getDefault());
|
||||
|
||||
Reference in New Issue
Block a user