-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MockHttpServletResponse reset() does not reset charset field #25501
Labels
in: test
Issues in the test module
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Comments
Thanks for raising the issue. I am able to reproduce it with the following test case, which throws the reported exception for the @Test
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 contentTypeHeader1 = response.getHeader(CONTENT_TYPE);
assertThatCode(() -> MimeType.valueOf(contentTypeHeader1)).doesNotThrowAnyException();
assertThat(contentTypeHeader1).isEqualTo("text/plain;charset=UTF-8");
response.reset();
// assertThat(response.isCharset()).isFalse();
response.setContentType("text/plain");
assertThat(response.getContentType()).isEqualTo("text/plain");
String contentTypeHeader2 = response.getHeader(CONTENT_TYPE);
assertThatCode(() -> MimeType.valueOf(contentTypeHeader2)).doesNotThrowAnyException();
assertThat(contentTypeHeader2).isEqualTo("text/plain");
} |
This has been fixed in Spring Framework Feel free to try it out in the upcoming 5.2.9 and 5.3 M2 snapshots. |
jhoeller
added a commit
that referenced
this issue
Aug 7, 2020
jhoeller
added a commit
that referenced
this issue
Aug 7, 2020
jhoeller
added a commit
that referenced
this issue
Aug 7, 2020
FelixFly
pushed a commit
to FelixFly/spring-framework
that referenced
this issue
Aug 16, 2020
Prior to this commit, calling reset() on MockHttpServletResponse did not reset the `charset` field to `false` which could result in the "Content-Type" header containing `;charset=null` which in turn would result in errors when parsing the "Content-Type" header. This commit resets the charset field to `false` in MockHttpServletResponse's reset() method to avoid such errors. Closes spring-projectsgh-25501
Merged
6 tasks
zx20110729
pushed a commit
to zx20110729/spring-framework
that referenced
this issue
Feb 18, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
in: test
Issues in the test module
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Affects: 5.2.7.RELEASE
When calling the
reset()
method ofMockHttpServletResponse
, the booleancharset
is not reset to false.If the response object had the charset set before being reset,
charset=null
is appended to the mime type.This can lead to an
InvalidMediaTypeException
:The text was updated successfully, but these errors were encountered: