Merge branch '5.2.x'

This commit is contained in:
Sam Brannen 2020-08-01 14:02:22 +02:00
commit 58412affaa
3 changed files with 25 additions and 0 deletions

View File

@ -331,6 +331,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
public void reset() {
resetBuffer();
this.characterEncoding = null;
this.charset = false;
this.contentLength = 0;
this.contentType = null;
this.locale = Locale.getDefault();

View File

@ -481,4 +481,27 @@ class MockHttpServletResponseTests {
assertThat(((MockCookie) cookie).getSameSite()).isEqualTo("Lax");
}
@Test // gh-25501
void resetResetsCharset() {
assertThat(response.isCharset()).isFalse();
response.setCharacterEncoding("UTF-8");
assertThat(response.isCharset()).isTrue();
assertThat(response.getCharacterEncoding()).isEqualTo("UTF-8");
response.setContentType("text/plain");
assertThat(response.getContentType()).isEqualTo("text/plain");
String contentTypeHeader = response.getHeader(CONTENT_TYPE);
assertThat(contentTypeHeader).isEqualTo("text/plain;charset=UTF-8");
response.reset();
assertThat(response.isCharset()).isFalse();
// Do not invoke setCharacterEncoding() since that sets the charset flag to true.
// response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
assertThat(response.isCharset()).isFalse(); // should still be false
assertThat(response.getContentType()).isEqualTo("text/plain");
contentTypeHeader = response.getHeader(CONTENT_TYPE);
assertThat(contentTypeHeader).isEqualTo("text/plain");
}
}

View File

@ -331,6 +331,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
public void reset() {
resetBuffer();
this.characterEncoding = null;
this.charset = false;
this.contentLength = 0;
this.contentType = null;
this.locale = Locale.getDefault();