Quote question marks in content-disposition

This commit ensures that question marks are encoded, in accordance
with RFC 2047, section 4.2, rule (3).

Closes gh-30252
This commit is contained in:
luozhenyu 2023-03-31 14:16:37 +08:00 committed by Arjen Poutsma
parent a465b16f7c
commit 5a4a46af78
2 changed files with 17 additions and 1 deletions

View File

@ -599,7 +599,7 @@ public final class ContentDisposition {
} }
private static boolean isPrintable(byte c) { private static boolean isPrintable(byte c) {
return (c >= '!' && c <= '<') || (c >= '>' && c <= '~'); return (c >= '!' && c <= '<') || (c >= '@' && c <= '~') || c == '>';
} }
private static String encodeQuotedPairs(String filename) { private static String encodeQuotedPairs(String filename) {

View File

@ -325,4 +325,20 @@ class ContentDispositionTests {
assertThat(parsed.toString()).isEqualTo(cd.toString()); assertThat(parsed.toString()).isEqualTo(cd.toString());
} }
@Test // gh-30252
void parseFormattedWithQuestionMark() {
String filename = "filename with ?问号.txt";
ContentDisposition cd = ContentDisposition.attachment()
.filename(filename, StandardCharsets.UTF_8)
.build();
String[] parts = cd.toString().split("; ");
String quotedPrintableFilename = parts[0] + "; " + parts[1];
assertThat(ContentDisposition.parse(quotedPrintableFilename).getFilename())
.isEqualTo(filename);
String rfc5987Filename = parts[0] + "; " + parts[2];
assertThat(ContentDisposition.parse(rfc5987Filename).getFilename())
.isEqualTo(filename);
}
} }