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:
parent
a465b16f7c
commit
5a4a46af78
|
|
@ -599,7 +599,7 @@ public final class ContentDisposition {
|
|||
}
|
||||
|
||||
private static boolean isPrintable(byte c) {
|
||||
return (c >= '!' && c <= '<') || (c >= '>' && c <= '~');
|
||||
return (c >= '!' && c <= '<') || (c >= '@' && c <= '~') || c == '>';
|
||||
}
|
||||
|
||||
private static String encodeQuotedPairs(String filename) {
|
||||
|
|
|
|||
|
|
@ -325,4 +325,20 @@ class ContentDispositionTests {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue