Skip to content

Commit

Permalink
Support quoted boundary in DefaultPartHttpMessageReader
Browse files Browse the repository at this point in the history
This commit makes sure that quoted boundary parameters are supported in
the DefaultPartHttpMessageReader.

Closes gh-26616
  • Loading branch information
poutsma committed Mar 1, 2021
1 parent 4af7a68 commit 1a79c54
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ private static byte[] boundary(HttpMessage message) {
if (contentType != null) {
String boundary = contentType.getParameter("boundary");
if (boundary != null) {
int len = boundary.length();
if (len > 2 && boundary.charAt(0) == '"' && boundary.charAt(len - 1) == '"') {
boundary = boundary.substring(1, len - 1);
}
return boundary.getBytes(StandardCharsets.ISO_8859_1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@ public void tooManyParts() throws InterruptedException {
latch.await();
}

@ParameterizedDefaultPartHttpMessageReaderTest
public void quotedBoundary(String displayName, DefaultPartHttpMessageReader reader) throws InterruptedException {
MockServerHttpRequest request = createRequest(
new ClassPathResource("simple.multipart", getClass()), "\"simple-boundary\"");

Flux<Part> result = reader.read(forClass(Part.class), request, emptyMap());

CountDownLatch latch = new CountDownLatch(2);
StepVerifier.create(result)
.consumeNextWith(part -> testPart(part, null,
"This is implicitly typed plain ASCII text.\r\nIt does NOT end with a linebreak.", latch)).as("Part 1")
.consumeNextWith(part -> testPart(part, null,
"This is explicitly typed plain ASCII text.\r\nIt DOES end with a linebreak.\r\n", latch)).as("Part 2")
.verifyComplete();

latch.await();
}


private void testBrowser(DefaultPartHttpMessageReader reader, Resource resource, String boundary)
throws InterruptedException {

Expand Down

0 comments on commit 1a79c54

Please sign in to comment.