You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2016/02/26 12:22:13 UTC
cxf git commit: [CXF-6802] More support for encoded
Content-Disposition filenames
Repository: cxf
Updated Branches:
refs/heads/master e61a83d4a -> cab60c066
[CXF-6802] More support for encoded Content-Disposition filenames
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/cab60c06
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/cab60c06
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/cab60c06
Branch: refs/heads/master
Commit: cab60c066e94816cd42f45fcca34ad5626bc01d4
Parents: e61a83d
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Fri Feb 26 11:21:57 2016 +0000
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Fri Feb 26 11:21:57 2016 +0000
----------------------------------------------------------------------
.../cxf/attachment/ContentDisposition.java | 20 ++++++++++++++++++++
.../cxf/attachment/AttachmentUtilTest.java | 7 +++++++
2 files changed, 27 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/cab60c06/core/src/main/java/org/apache/cxf/attachment/ContentDisposition.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/attachment/ContentDisposition.java b/core/src/main/java/org/apache/cxf/attachment/ContentDisposition.java
index 1fdc4ee..330822d 100644
--- a/core/src/main/java/org/apache/cxf/attachment/ContentDisposition.java
+++ b/core/src/main/java/org/apache/cxf/attachment/ContentDisposition.java
@@ -36,6 +36,7 @@ public class ContentDisposition {
"(UTF-8|ISO-8859-1)''((?:%[0-9a-f]{2}|\\S)+)";
private static final Pattern CD_HEADER_EXT_PARAMS_PATTERN =
Pattern.compile(CD_HEADER_EXT_PARAMS_EXPRESSION);
+ private static final Pattern CODEPOINT_ENCODED_VALUE_PATTERN = Pattern.compile("&#[0-9]{4};|\\S");
private String value;
private String type;
@@ -86,6 +87,21 @@ public class ContentDisposition {
} catch (UnsupportedEncodingException e) {
// would be odd not to support UTF-8 or 8859-1
}
+ } else if ("filename".equals(paramName) && paramValue.contains("&#")) {
+ Matcher matcher = CODEPOINT_ENCODED_VALUE_PATTERN.matcher(paramValue);
+ StringBuilder sb = new StringBuilder();
+ while (matcher.find()) {
+ String matched = matcher.group();
+ if (matched.startsWith("&#")) {
+ int codePoint = Integer.valueOf(matched.substring(2, 6));
+ sb.append(Character.toChars(codePoint));
+ } else {
+ sb.append(matched.charAt(0));
+ }
+ }
+ if (sb.length() > 0) {
+ paramValue = sb.toString();
+ }
}
params.put(paramName, paramValue);
}
@@ -98,6 +114,10 @@ public class ContentDisposition {
return type;
}
+ public String getFilename() {
+ return params.get("filename");
+ }
+
public String getParameter(String name) {
return params.get(name);
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/cab60c06/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java b/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
index 6eeedd4..0c9f17d 100644
--- a/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
+++ b/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
@@ -77,6 +77,13 @@ public class AttachmentUtilTest extends Assert {
AttachmentUtil.getContentDispositionFileName(
"filename*=UTF-8''%e4%b8%96%e7%95%8c%e3%83%bc%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab.txt"));
}
+
+ @Test
+ public void testContendDispositionFileNameNoRfc5987() {
+ assertEquals("демо-сервис.zip",
+ AttachmentUtil.getContentDispositionFileName(
+ "filename=\"демо-сервис.zip\""));
+ }
}