cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6802] More support for encoded Content-Disposition filenames
Date Fri, 26 Feb 2016 11:23:45 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 96c7ecdeb -> a9418f290


[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/a9418f29
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a9418f29
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a9418f29

Branch: refs/heads/3.0.x-fixes
Commit: a9418f2909b65c16d5b8e6426c91c0765477dfcc
Parents: 96c7ecd
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Feb 26 11:21:57 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Feb 26 11:23:22 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/a9418f29/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/a9418f29/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=\"&#1076;&#1077;&#1084;&#1086;-&#1089;&#1077;&#1088;&#1074;&#1080;&#1089;.zip\""));
+    }
 
 }
 


Mime
View raw message