Skip to content

Commit

Permalink
fix #2786 Optimized Content-Disposition handling: use 'filename*' onl…
Browse files Browse the repository at this point in the history
…y for non-ASCII names.
  • Loading branch information
marevol committed Dec 7, 2023
1 parent 5b7b17f commit d38211e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/org/codelibs/fess/helper/ViewHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,16 @@ protected void writeFileName(final StreamResponse response, final ResponseData r
}

final String encodedName = URLEncoder.encode(name, Constants.UTF_8).replace("+", "%20");
response.header(CONTENT_DISPOSITION, contentDispositionType + "; filename=\"" + name + "\"; filename*=utf-8''" + encodedName);
final String contentDispositionValue;
if (name.equals(encodedName)) {
contentDispositionValue = contentDispositionType + "; filename=\"" + name + "\"";
} else {
contentDispositionValue = contentDispositionType + "; filename*=utf-8''" + encodedName;
}
if (logger.isDebugEnabled()) {
logger.debug("ResponseHeader: {}: {}", CONTENT_DISPOSITION, contentDispositionValue);
}
response.header(CONTENT_DISPOSITION, contentDispositionValue);
} catch (final Exception e) {
logger.warn("Failed to write a filename: {}", responseData, e);
}
Expand Down

0 comments on commit d38211e

Please sign in to comment.