Skip to content

Commit

Permalink
Quote question marks in content-disposition
Browse files Browse the repository at this point in the history
Closes gh-30252
  • Loading branch information
luozhenyu committed Mar 31, 2023
1 parent d451d6a commit 84117e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ private static String encodeQuotedPrintableFilename(String filename, Charset cha
}

private static boolean isPrintable(byte c) {
return (c >= '!' && c <= '<') || (c >= '>' && c <= '~');
return (c >= '!' && c <= '<') || (c >= '@' && c <= '~') || c == '>';
}

private static String encodeQuotedPairs(String filename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,20 @@ void parseFormatted() {
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);
}
}

0 comments on commit 84117e8

Please sign in to comment.