File tree 3 files changed +13
-2
lines changed
main/java/org/springframework/mock/web
test/java/org/springframework/mock/web
spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet 3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -488,7 +488,8 @@ public void setContentType(@Nullable String contentType) {
488
488
}
489
489
catch (IllegalArgumentException ex ) {
490
490
// Try to get charset value anyway
491
- int charsetIndex = contentType .toLowerCase ().indexOf (CHARSET_PREFIX );
491
+ contentType = contentType .toLowerCase ();
492
+ int charsetIndex = contentType .indexOf (CHARSET_PREFIX );
492
493
if (charsetIndex != -1 ) {
493
494
this .characterEncoding = contentType .substring (charsetIndex + CHARSET_PREFIX .length ());
494
495
}
Original file line number Diff line number Diff line change @@ -185,6 +185,15 @@ void setContentTypeUTF8() {
185
185
assertThat (request .getCharacterEncoding ()).isEqualTo ("UTF-8" );
186
186
}
187
187
188
+ @ Test // gh-29255
189
+ void setContentTypeInvalidWithNonAsciiCharacterAndCharset () {
190
+ String contentType = "İcharset=" ;
191
+ request .addHeader (HttpHeaders .CONTENT_TYPE , contentType );
192
+ assertThat (request .getContentType ()).isEqualTo (contentType );
193
+ assertThat (request .getHeader (HttpHeaders .CONTENT_TYPE )).isEqualTo (contentType );
194
+ assertThat (request .getCharacterEncoding ()).isEqualTo ("" );
195
+ }
196
+
188
197
@ Test
189
198
void contentTypeHeader () {
190
199
String contentType = "test/plain" ;
Original file line number Diff line number Diff line change @@ -488,7 +488,8 @@ public void setContentType(@Nullable String contentType) {
488
488
}
489
489
catch (IllegalArgumentException ex ) {
490
490
// Try to get charset value anyway
491
- int charsetIndex = contentType .toLowerCase ().indexOf (CHARSET_PREFIX );
491
+ contentType = contentType .toLowerCase ();
492
+ int charsetIndex = contentType .indexOf (CHARSET_PREFIX );
492
493
if (charsetIndex != -1 ) {
493
494
this .characterEncoding = contentType .substring (charsetIndex + CHARSET_PREFIX .length ());
494
495
}
You can’t perform that action at this time.
0 commit comments