File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed
main/java/org/springframework/mock/web
test/java/org/springframework/mock/web
spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -331,6 +331,7 @@ public boolean isCommitted() {
331
331
public void reset () {
332
332
resetBuffer ();
333
333
this .characterEncoding = null ;
334
+ this .charset = false ;
334
335
this .contentLength = 0 ;
335
336
this .contentType = null ;
336
337
this .locale = Locale .getDefault ();
Original file line number Diff line number Diff line change @@ -481,4 +481,27 @@ private void assertPrimarySessionCookie(String expectedValue) {
481
481
assertThat (((MockCookie ) cookie ).getSameSite ()).isEqualTo ("Lax" );
482
482
}
483
483
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
+
484
507
}
Original file line number Diff line number Diff line change @@ -331,6 +331,7 @@ public boolean isCommitted() {
331
331
public void reset () {
332
332
resetBuffer ();
333
333
this .characterEncoding = null ;
334
+ this .charset = false ;
334
335
this .contentLength = 0 ;
335
336
this .contentType = null ;
336
337
this .locale = Locale .getDefault ();
You can’t perform that action at this time.
0 commit comments