Skip to content

Commit 1a79c54

Browse files
committed
Support quoted boundary in DefaultPartHttpMessageReader
This commit makes sure that quoted boundary parameters are supported in the DefaultPartHttpMessageReader. Closes gh-26616
1 parent 4af7a68 commit 1a79c54

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

spring-web/src/main/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ private static byte[] boundary(HttpMessage message) {
227227
if (contentType != null) {
228228
String boundary = contentType.getParameter("boundary");
229229
if (boundary != null) {
230+
int len = boundary.length();
231+
if (len > 2 && boundary.charAt(0) == '"' && boundary.charAt(len - 1) == '"') {
232+
boundary = boundary.substring(1, len - 1);
233+
}
230234
return boundary.getBytes(StandardCharsets.ISO_8859_1);
231235
}
232236
}

spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,25 @@ public void tooManyParts() throws InterruptedException {
233233
latch.await();
234234
}
235235

236+
@ParameterizedDefaultPartHttpMessageReaderTest
237+
public void quotedBoundary(String displayName, DefaultPartHttpMessageReader reader) throws InterruptedException {
238+
MockServerHttpRequest request = createRequest(
239+
new ClassPathResource("simple.multipart", getClass()), "\"simple-boundary\"");
240+
241+
Flux<Part> result = reader.read(forClass(Part.class), request, emptyMap());
242+
243+
CountDownLatch latch = new CountDownLatch(2);
244+
StepVerifier.create(result)
245+
.consumeNextWith(part -> testPart(part, null,
246+
"This is implicitly typed plain ASCII text.\r\nIt does NOT end with a linebreak.", latch)).as("Part 1")
247+
.consumeNextWith(part -> testPart(part, null,
248+
"This is explicitly typed plain ASCII text.\r\nIt DOES end with a linebreak.\r\n", latch)).as("Part 2")
249+
.verifyComplete();
250+
251+
latch.await();
252+
}
253+
254+
236255
private void testBrowser(DefaultPartHttpMessageReader reader, Resource resource, String boundary)
237256
throws InterruptedException {
238257

0 commit comments

Comments
 (0)