Skip to content

Commit 764d35c

Browse files
committed
Merge branch '6.2.x'
2 parents 6bbfd56 + 696692f commit 764d35c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpReques
147147
ServerCodecConfigurer configurer, String logPrefix) {
148148

149149
MediaType contentType = getContentType(request);
150-
if (contentType == null || !contentType.isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED)) {
150+
if (contentType == null || !contentType.isConcrete() || !contentType.isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED)) {
151151
return EMPTY_FORM_DATA;
152152
}
153153

154-
HttpMessageReader<MultiValueMap<String, String>> reader = getReader(configurer, MediaType.APPLICATION_FORM_URLENCODED, FORM_DATA_TYPE);
154+
HttpMessageReader<MultiValueMap<String, String>> reader = getReader(configurer, contentType, FORM_DATA_TYPE);
155155
if (reader == null) {
156156
return Mono.error(new IllegalStateException("No HttpMessageReader for " + contentType));
157157
}
@@ -165,7 +165,7 @@ private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpReques
165165
private Mono<MultiValueMap<String, Part>> initMultipartData(ServerCodecConfigurer configurer, String logPrefix) {
166166

167167
MediaType contentType = getContentType(this.request);
168-
if (contentType == null || !contentType.getType().equalsIgnoreCase("multipart")) {
168+
if (contentType == null || !contentType.isConcrete() || !contentType.getType().equalsIgnoreCase("multipart")) {
169169
return EMPTY_MULTIPART_DATA;
170170
}
171171

spring-web/src/test/java/org/springframework/web/server/adapter/DefaultServerWebExchangeTests.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.springframework.http.HttpHeaders;
2222
import org.springframework.http.MediaType;
2323
import org.springframework.http.codec.ServerCodecConfigurer;
24+
import org.springframework.http.codec.multipart.Part;
2425
import org.springframework.util.MultiValueMap;
2526
import org.springframework.web.server.ServerWebExchange;
2627
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
@@ -60,14 +61,25 @@ void transformUrlWithMultipleEncoders() {
6061
}
6162

6263
@Test // gh-34660
63-
void useFormDataMessageReaderWhenAllContentType() {
64+
void shouldNotDecodeFormDataWhenContentTypeNotConcrete() {
6465
MockServerHttpRequest request = MockServerHttpRequest
6566
.post("https://example.com")
6667
.header(HttpHeaders.CONTENT_TYPE, MediaType.ALL_VALUE)
6768
.body("project=spring");
6869
ServerWebExchange exchange = createExchange(request);
6970
MultiValueMap<String, String> body = exchange.getFormData().block();
70-
assertThat(body.get("project")).contains("spring");
71+
assertThat(body).isEmpty();
72+
}
73+
74+
@Test // gh-34660
75+
void shouldNotDecodeMultipartWhenContentTypeNotConcrete() {
76+
MockServerHttpRequest request = MockServerHttpRequest
77+
.post("https://example.com")
78+
.header(HttpHeaders.CONTENT_TYPE, "multipart/*")
79+
.body("project=spring");
80+
ServerWebExchange exchange = createExchange(request);
81+
MultiValueMap<String, Part> body = exchange.getMultipartData().block();
82+
assertThat(body).isEmpty();
7183
}
7284

7385

0 commit comments

Comments
 (0)