Skip to content

Quote '?' in Quoted Printable filename #30252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}