Skip to content

Commit 2ff3d53

Browse files
committed
Ignore parse errors in HttpPutFormContentFilter
Errors when parsing the request content-type, in order to find out if the request has form content, are translated to false. Issue: SPR-9769
1 parent 48b963a commit 2ff3d53

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

spring-web/src/main/java/org/springframework/web/filter/HttpPutFormContentFilter.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,18 @@ public InputStream getBody() throws IOException {
8787
else {
8888
filterChain.doFilter(request, response);
8989
}
90-
9190
}
9291

9392
private boolean isFormContentType(HttpServletRequest request) {
9493
String contentType = request.getContentType();
9594
if (contentType != null) {
96-
MediaType mediaType = MediaType.parseMediaType(contentType);
97-
return (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType));
95+
try {
96+
MediaType mediaType = MediaType.parseMediaType(contentType);
97+
return (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType));
98+
}
99+
catch (IllegalArgumentException ex) {
100+
return false;
101+
}
98102
}
99103
else {
100104
return false;

spring-web/src/test/java/org/springframework/web/filter/HttpPutFormContentFilterTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ public void wrapFormEncodedOnly() throws Exception {
8787
}
8888
}
8989

90+
@Test
91+
public void invalidMediaType() throws Exception {
92+
request.setContent("".getBytes("ISO-8859-1"));
93+
request.setContentType("foo");
94+
filterChain = new MockFilterChain();
95+
filter.doFilter(request, response, filterChain);
96+
assertSame(request, filterChain.getRequest());
97+
}
98+
9099
@Test
91100
public void getParameter() throws Exception {
92101
request.setContent("name=value".getBytes("ISO-8859-1"));

0 commit comments

Comments
 (0)