Repository: cxf
Updated Branches:
  refs/heads/master 0eeeccd94 -> 348095868


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

Branch: refs/heads/master
Commit: 348095868d8d0e7ed363c65bfd2c05c1f691b479
Parents: 0eeeccd
Author: Sergey Beryozkin <sberyoz...@gmail.com>
Authored: Fri Aug 12 16:34:45 2016 +0100
Committer: Sergey Beryozkin <sberyoz...@gmail.com>
Committed: Fri Aug 12 16:34:45 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/34809586/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/34809586/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\""));
+    }
 }

Reply via email to