瀏覽代碼

fix #2786 Optimized Content-Disposition handling: use 'filename*' only for non-ASCII names.

Shinsuke Sugaya 1 年之前
父節點
當前提交
d38211eadf
共有 1 個文件被更改,包括 10 次插入1 次删除
  1. 10 1
      src/main/java/org/codelibs/fess/helper/ViewHelper.java

+ 10 - 1
src/main/java/org/codelibs/fess/helper/ViewHelper.java

@@ -745,7 +745,16 @@ public class ViewHelper {
             }
             }
 
 
             final String encodedName = URLEncoder.encode(name, Constants.UTF_8).replace("+", "%20");
             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) {
         } catch (final Exception e) {
             logger.warn("Failed to write a filename: {}", responseData, e);
             logger.warn("Failed to write a filename: {}", responseData, e);
         }
         }