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-6729] Updating CookieHeaderProvider too
Date Thu, 14 Jan 2016 17:24:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes e9bb1d30d -> dac3e9e25


[CXF-6729] Updating CookieHeaderProvider too


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

Branch: refs/heads/3.1.x-fixes
Commit: dac3e9e2567dbd8e007f0d08afe252097c9f035a
Parents: e9bb1d3
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Jan 14 17:23:03 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Jan 14 17:23:59 2016 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/impl/CookieHeaderProvider.java    | 22 ++++++++------------
 .../cxf/jaxrs/impl/NewCookieHeaderProvider.java | 17 +++++++++++----
 .../jaxrs/impl/CookieHeaderProviderTest.java    |  8 +++++++
 3 files changed, 30 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/dac3e9e2/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
index fd35af5..f0a3b3e 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
@@ -29,8 +29,6 @@ public class CookieHeaderProvider implements HeaderDelegate<Cookie>
{
     private static final String PATH = "$Path";
     private static final String DOMAIN = "$Domain";
     
-    private static final String DOUBLE_QUOTE = "\""; 
-    
     public Cookie fromString(String c) {
         
         if (c == null) {
@@ -48,16 +46,18 @@ public class CookieHeaderProvider implements HeaderDelegate<Cookie>
{
         for (String token : tokens) {
             String theToken = token.trim();
             if (theToken.startsWith(VERSION)) {
-                version = Integer.parseInt(stripQuotes(theToken.substring(VERSION.length()
+ 1)));
+                version = Integer.parseInt(
+                    NewCookieHeaderProvider.stripQuotes(theToken.substring(VERSION.length()
+ 1)));
             } else if (theToken.startsWith(PATH)) {
-                path = stripQuotes(theToken.substring(PATH.length() + 1));
+                path = NewCookieHeaderProvider.stripQuotes(theToken.substring(PATH.length()
+ 1));
             } else if (theToken.startsWith(DOMAIN)) {
-                domain = stripQuotes(theToken.substring(DOMAIN.length() + 1));
+                domain = NewCookieHeaderProvider.stripQuotes(theToken.substring(DOMAIN.length()
+ 1));
             } else {
                 int i = theToken.indexOf('=');
                 if (i != -1) {
                     name = theToken.substring(0, i);
-                    value = i == theToken.length()  + 1 ? "" : stripQuotes(theToken.substring(i
+ 1));
+                    value = i == theToken.length()  + 1 ? "" 
+                        : NewCookieHeaderProvider.stripQuotes(theToken.substring(i + 1));
                 }
             }
         }
@@ -69,22 +69,18 @@ public class CookieHeaderProvider implements HeaderDelegate<Cookie>
{
         return new Cookie(name, value, path, domain, version);
     }
 
-    private String stripQuotes(String value) {
-        return value.replaceAll(DOUBLE_QUOTE, "");
-    }
-    
     public String toString(Cookie c) {
         StringBuilder sb = new StringBuilder();
         
         if (c.getVersion() != 0) {
             sb.append(VERSION).append('=').append(c.getVersion()).append(';');
         }
-        sb.append(c.getName()).append('=').append(c.getValue());
+        sb.append(c.getName()).append('=').append(NewCookieHeaderProvider.maybeQuote(c.getValue()));
         if (c.getPath() != null) {
-            sb.append(';').append(PATH).append('=').append(c.getPath());
+            sb.append(';').append(PATH).append('=').append(NewCookieHeaderProvider.maybeQuote(c.getPath()));
         }
         if (c.getDomain() != null) {
-            sb.append(';').append(DOMAIN).append('=').append(c.getDomain());
+            sb.append(';').append(DOMAIN).append('=').append(NewCookieHeaderProvider.maybeQuote(c.getDomain()));
         }
         return sb.toString();
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/dac3e9e2/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
index 5a5a472..4bcfd5e 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
@@ -40,6 +40,7 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
     
     /** from RFC 2068, token special case characters */
     private static final String TSPECIALS = "\"()<>@,;:\\/[]?={} \t";
+    private static final String DOUBLE_QUOTE = "\""; 
         
     public NewCookie fromString(String c) {
         
@@ -66,8 +67,8 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
             String paramName = sepIndex != -1 ? theToken.substring(0, sepIndex) : theToken;
             String paramValue = sepIndex == -1 || sepIndex == theToken.length() - 1 
                 ? null : theToken.substring(sepIndex + 1);
-            if (paramValue != null && paramValue.startsWith("\"")) {
-                paramValue = paramValue.substring(1, paramValue.length() - 1);
+            if (paramValue != null) {
+                paramValue = stripQuotes(paramValue);
             }
             
             if (paramName.equalsIgnoreCase(MAX_AGE)) {
@@ -141,7 +142,7 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
      * @param value
      * @return String
      */
-    private static String maybeQuote(String value) {
+    static String maybeQuote(String value) {
         
         StringBuilder buff = new StringBuilder();
         // handle a null value as well as an empty one, attr=
@@ -164,7 +165,7 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
      * @param value
      * @return boolean
      */
-    private static boolean needsQuote(String value) {
+    static boolean needsQuote(String value) {
         if (null == value) {
             return true;
         }
@@ -185,4 +186,12 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
         }
         return false;
     }
+    
+    static String stripQuotes(String paramValue) {
+        if (paramValue.startsWith(DOUBLE_QUOTE)
+            && paramValue.endsWith(DOUBLE_QUOTE) && paramValue.length() >
1) {
+            paramValue = paramValue.substring(1, paramValue.length() - 1);
+        }
+        return paramValue;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/dac3e9e2/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CookieHeaderProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CookieHeaderProviderTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CookieHeaderProviderTest.java
index 61d606d..22b885f 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CookieHeaderProviderTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/CookieHeaderProviderTest.java
@@ -61,6 +61,14 @@ public class CookieHeaderProviderTest extends Assert {
     }
     
     @Test
+    public void testToStringWithQuotes() {
+        Cookie c = new Cookie("foo", "bar z", "path", "domain", 2);
+        assertEquals("$Version=2;foo=\"bar z\";$Path=path;$Domain=domain", 
+                     c.toString());
+               
+    }
+    
+    @Test
     public void testCookieWithQuotes() {
         Cookie c = Cookie.valueOf("$Version=\"1\"; foo=\"bar\"; $Path=\"/path\"");
         assertTrue("bar".equals(c.getValue())


Mime
View raw message