Improve MockHttpServletRequest/Response charset parsing

Issue: SPR-12677
This commit is contained in:
Rossen Stoyanchev
2015-03-20 16:12:46 -04:00
parent a57d42829c
commit f06dffb714
6 changed files with 88 additions and 19 deletions

View File

@@ -100,6 +100,17 @@ public class MockHttpServletRequestTests {
assertEquals("UTF-8", request.getCharacterEncoding());
}
// SPR-12677
@Test
public void setContentTypeHeaderWithMoreComplexCharsetSyntax() {
String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar";
request.addHeader("Content-Type", contentType);
assertEquals(contentType, request.getContentType());
assertEquals(contentType, request.getHeader("Content-Type"));
assertEquals("UTF-8", request.getCharacterEncoding());
}
@Test
public void setContentTypeThenCharacterEncoding() {
request.setContentType("test/plain");

View File

@@ -90,6 +90,23 @@ public class MockHttpServletResponseTests {
assertEquals("UTF-8", response.getCharacterEncoding());
}
// SPR-12677
@Test
public void contentTypeHeaderWithMoreComplexCharsetSyntax() {
String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar";
response.setHeader("Content-Type", contentType);
assertEquals(contentType, response.getContentType());
assertEquals(contentType, response.getHeader("Content-Type"));
assertEquals("UTF-8", response.getCharacterEncoding());
response = new MockHttpServletResponse();
response.addHeader("Content-Type", contentType);
assertEquals(contentType, response.getContentType());
assertEquals(contentType, response.getHeader("Content-Type"));
assertEquals("UTF-8", response.getCharacterEncoding());
}
@Test
public void setContentTypeThenCharacterEncoding() {
response.setContentType("test/plain");