Skip to content

Commit e88e8f1

Browse files
committed
MockHttpServletRequestBuilder reliably detects form body content type again
Issue: SPR-15116
1 parent bb9e561 commit e88e8f1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
* {@code MockHttpServletRequest} can be plugged in via {@link #with(RequestPostProcessor)}.
7171
*
7272
* @author Rossen Stoyanchev
73+
* @author Juergen Hoeller
7374
* @author Arjen Poutsma
7475
* @author Sam Brannen
7576
* @author Kamill Sokol
@@ -630,10 +631,13 @@ public final MockHttpServletRequest buildRequest(ServletContext servletContext)
630631
}
631632
}
632633

633-
if (this.content != null && this.contentType != null) {
634-
MediaType mediaType = MediaType.parseMediaType(this.contentType);
635-
if (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType)) {
636-
addRequestParams(request, parseFormData(mediaType));
634+
if (this.content != null && this.content.length > 0) {
635+
String requestContentType = request.getContentType();
636+
if (requestContentType != null) {
637+
MediaType mediaType = MediaType.parseMediaType(requestContentType);
638+
if (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType)) {
639+
addRequestParams(request, parseFormData(mediaType));
640+
}
637641
}
638642
}
639643

0 commit comments

Comments
 (0)