From 71291bd7ea87723e674bbb13a31b7b5a7b8e1079 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 18 Apr 2015 22:11:34 +0200 Subject: [PATCH 1/2] fix wrong uft-8 filenames on raw download, see issue #697 --- .../main/java/sonia/scm/util/HttpUtil.java | 31 +++++++++++++++---- .../rest/resources/RepositoryResource.java | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/util/HttpUtil.java b/scm-core/src/main/java/sonia/scm/util/HttpUtil.java index 4b40214051..68d669d914 100644 --- a/scm-core/src/main/java/sonia/scm/util/HttpUtil.java +++ b/scm-core/src/main/java/sonia/scm/util/HttpUtil.java @@ -73,18 +73,18 @@ public final class HttpUtil /** Field description */ public static final String ENCODING = "UTF-8"; - /** - * location header - * @since 1.43 - */ - public static final String HEADER_LOCATION = "Location"; - /** * content-length header * @since 1.46 */ public static final String HEADER_CONTENT_LENGTH = "Content-Length"; + /** + * location header + * @since 1.43 + */ + public static final String HEADER_LOCATION = "Location"; + /** * header for identifying the scm-manager client * @since 1.19 @@ -296,6 +296,25 @@ public final class HttpUtil } } + /** + * Creates the value for the content-disposition attachment header. The method + * creates the filename as specified in rfc6266. + * + * @param name attachment name + * @see rfc6266 section 5 + * @return value of content-disposition header + * @since 1.46 + */ + public static String createContentDispositionAttachmentHeader(String name) + { + StringBuilder buffer = new StringBuilder("attachment; "); + + buffer.append("filename=\"").append(name).append("\"; "); + buffer.append("filename*=utf-8''").append(encode(name)); + + return buffer.toString(); + } + /** * Method description * diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java index a6a494d5ca..afba957adb 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java @@ -1141,7 +1141,7 @@ public class RepositoryResource */ private String getContentDispositionName(String name) { - return "attachment; filename=\"".concat(name).concat("\""); + return HttpUtil.createContentDispositionAttachmentHeader(name); } /** From cb68170c5dfcb9a3e8ef21fd5a088614648c9fc9 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 17 May 2015 12:28:23 +0200 Subject: [PATCH 2/2] close branch issue-697