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-6989] Avoding a reg-ex split when processing Content-Disposition properties
Date Fri, 12 Aug 2016 15:36:40 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes f63e8ad71 -> f454461fc


[CXF-6989] Avoding a reg-ex split when processing Content-Disposition properties


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/f454461f
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f454461f
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f454461f

Branch: refs/heads/3.1.x-fixes
Commit: f454461fc3e449d93f296e391a8b4360f82b4321
Parents: f63e8ad
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Aug 12 16:34:45 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Aug 12 16:36:28 2016 +0100

----------------------------------------------------------------------
 .../apache/cxf/attachment/ContentDisposition.java   | 16 +++++++++++++---
 .../apache/cxf/attachment/AttachmentUtilTest.java   |  5 +++++
 2 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f454461f/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 22b5daa..9ce30e9 100644
--- a/core/src/main/java/org/apache/cxf/attachment/ContentDisposition.java
+++ b/core/src/main/java/org/apache/cxf/attachment/ContentDisposition.java
@@ -56,9 +56,19 @@ public class ContentDisposition {
         String extendedFilename = null;
         Matcher m = CD_HEADER_PARAMS_PATTERN.matcher(tempValue);
         while (m.find()) {
-            String[] pair = m.group().trim().split("=");
-            String paramName = pair[0].trim();
-            String paramValue = pair.length == 2 ? pair[1].trim().replace("\"", "") : "";
+            String paramName = null;
+            String paramValue = "";
+            
+            String groupValue = m.group().trim();
+            int eqIndex = groupValue.indexOf('=');
+            if (eqIndex > 0) {
+                paramName = groupValue.substring(0, eqIndex).trim();
+                if (eqIndex + 1 != groupValue.length()) {
+                    paramValue = groupValue.substring(eqIndex + 1).trim().replace("\"", "");
+                }
+            } else {
+                paramName = groupValue;
+            }
             // filename* looks like the only CD param that is human readable
             // and worthy of the extended encoding support. Other parameters
             // can be supported if needed, see the complete list below

http://git-wip-us.apache.org/repos/asf/cxf/blob/f454461f/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 a9d3c90..d0601ff 100644
--- a/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
+++ b/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
@@ -109,4 +109,9 @@ public class AttachmentUtilTest extends Assert {
                 "filename=\"&#1076;&#1077;&#1084;&#1086;-&#1089;&#1077;&#1088;&#1074;&#1080;&#1089;.zip\""));
     }
 
+    @Test
+    public void testContentDispositionFnEquals() {
+        assertEquals("a=b.txt",
+            AttachmentUtil.getContentDispositionFileName("filename=\"a=b.txt\""));
+    }
 }


Mime
View raw message