Skip to content

Commit 84117e8

Browse files
committed
Quote question marks in content-disposition
Closes gh-30252
1 parent d451d6a commit 84117e8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: spring-web/src/main/java/org/springframework/http/ContentDisposition.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ private static String encodeQuotedPrintableFilename(String filename, Charset cha
599599
}
600600

601601
private static boolean isPrintable(byte c) {
602-
return (c >= '!' && c <= '<') || (c >= '>' && c <= '~');
602+
return (c >= '!' && c <= '<') || (c >= '@' && c <= '~') || c == '>';
603603
}
604604

605605
private static String encodeQuotedPairs(String filename) {

Diff for: spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java

+16
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,20 @@ void parseFormatted() {
325325
assertThat(parsed.toString()).isEqualTo(cd.toString());
326326
}
327327

328+
@Test // gh-30252
329+
void parseFormattedWithQuestionMark() {
330+
String filename = "filename with ?问号.txt";
331+
ContentDisposition cd = ContentDisposition.attachment()
332+
.filename(filename, StandardCharsets.UTF_8)
333+
.build();
334+
String[] parts = cd.toString().split("; ");
335+
336+
String quotedPrintableFilename = parts[0] + "; " + parts[1];
337+
assertThat(ContentDisposition.parse(quotedPrintableFilename).getFilename())
338+
.isEqualTo(filename);
339+
340+
String rfc5987Filename = parts[0] + "; " + parts[2];
341+
assertThat(ContentDisposition.parse(rfc5987Filename).getFilename())
342+
.isEqualTo(filename);
343+
}
328344
}

0 commit comments

Comments
 (0)