Skip to content

Commit 58412af

Browse files
committed
Merge branch '5.2.x'
2 parents 6f716e6 + 5576321 commit 58412af

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ public boolean isCommitted() {
331331
public void reset() {
332332
resetBuffer();
333333
this.characterEncoding = null;
334+
this.charset = false;
334335
this.contentLength = 0;
335336
this.contentType = null;
336337
this.locale = Locale.getDefault();

spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,27 @@ private void assertPrimarySessionCookie(String expectedValue) {
481481
assertThat(((MockCookie) cookie).getSameSite()).isEqualTo("Lax");
482482
}
483483

484+
@Test // gh-25501
485+
void resetResetsCharset() {
486+
assertThat(response.isCharset()).isFalse();
487+
response.setCharacterEncoding("UTF-8");
488+
assertThat(response.isCharset()).isTrue();
489+
assertThat(response.getCharacterEncoding()).isEqualTo("UTF-8");
490+
response.setContentType("text/plain");
491+
assertThat(response.getContentType()).isEqualTo("text/plain");
492+
String contentTypeHeader = response.getHeader(CONTENT_TYPE);
493+
assertThat(contentTypeHeader).isEqualTo("text/plain;charset=UTF-8");
494+
495+
response.reset();
496+
497+
assertThat(response.isCharset()).isFalse();
498+
// Do not invoke setCharacterEncoding() since that sets the charset flag to true.
499+
// response.setCharacterEncoding("UTF-8");
500+
response.setContentType("text/plain");
501+
assertThat(response.isCharset()).isFalse(); // should still be false
502+
assertThat(response.getContentType()).isEqualTo("text/plain");
503+
contentTypeHeader = response.getHeader(CONTENT_TYPE);
504+
assertThat(contentTypeHeader).isEqualTo("text/plain");
505+
}
506+
484507
}

spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ public boolean isCommitted() {
331331
public void reset() {
332332
resetBuffer();
333333
this.characterEncoding = null;
334+
this.charset = false;
334335
this.contentLength = 0;
335336
this.contentType = null;
336337
this.locale = Locale.getDefault();

0 commit comments

Comments
 (0)