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] Not quoting Path with forward slash characters
Date Thu, 07 Apr 2016 09:40:51 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 20a3ddb13 -> f64ee3c26


[CXF-6729] Not quoting Path with forward slash characters


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

Branch: refs/heads/3.0.x-fixes
Commit: f64ee3c26e69f76dae9bf58bd0ab16be514a1ec5
Parents: 20a3ddb
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Apr 7 10:37:42 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Apr 7 10:40:32 2016 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/impl/CookieHeaderProvider.java    |  6 +--
 .../cxf/jaxrs/impl/NewCookieHeaderProvider.java | 40 +++++++++++---------
 .../jaxrs/impl/NewCookieHeaderProviderTest.java |  6 +++
 3 files changed, 32 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f64ee3c2/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 f0a3b3e..89df061 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
@@ -75,12 +75,12 @@ public class CookieHeaderProvider implements HeaderDelegate<Cookie>
{
         if (c.getVersion() != 0) {
             sb.append(VERSION).append('=').append(c.getVersion()).append(';');
         }
-        sb.append(c.getName()).append('=').append(NewCookieHeaderProvider.maybeQuote(c.getValue()));
+        sb.append(c.getName()).append('=').append(NewCookieHeaderProvider.maybeQuoteAll(c.getValue()));
         if (c.getPath() != null) {
-            sb.append(';').append(PATH).append('=').append(NewCookieHeaderProvider.maybeQuote(c.getPath()));
+            sb.append(';').append(PATH).append('=').append(NewCookieHeaderProvider.maybeQuotePath(c.getPath()));
         }
         if (c.getDomain() != null) {
-            sb.append(';').append(DOMAIN).append('=').append(NewCookieHeaderProvider.maybeQuote(c.getDomain()));
+            sb.append(';').append(DOMAIN).append('=').append(NewCookieHeaderProvider.maybeQuoteAll(c.getDomain()));
         }
         return sb.toString();
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/f64ee3c2/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 4bcfd5e..601edb8 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
@@ -39,7 +39,9 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
     private static final String HTTP_ONLY = "HttpOnly";
     
     /** from RFC 2068, token special case characters */
-    private static final String TSPECIALS = "\"()<>@,;:\\/[]?={} \t";
+    
+    private static final String TSPECIALS_PATH = "\"()<>@,;:\\[]?={} \t";
+    private static final String TSPECIALS_ALL = TSPECIALS_PATH + "/";
     private static final String DOUBLE_QUOTE = "\""; 
         
     public NewCookie fromString(String c) {
@@ -108,18 +110,18 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
         }
 
         StringBuilder sb = new StringBuilder();
-        sb.append(value.getName()).append('=').append(maybeQuote(value.getValue()));
+        sb.append(value.getName()).append('=').append(maybeQuoteAll(value.getValue()));
         if (value.getComment() != null) {
-            sb.append(';').append(COMMENT).append('=').append(maybeQuote(value.getComment()));
+            sb.append(';').append(COMMENT).append('=').append(maybeQuoteAll(value.getComment()));
         }
         if (value.getDomain() != null) {
-            sb.append(';').append(DOMAIN).append('=').append(maybeQuote(value.getDomain()));
+            sb.append(';').append(DOMAIN).append('=').append(maybeQuoteAll(value.getDomain()));
         }
         if (value.getMaxAge() != -1) {
             sb.append(';').append(MAX_AGE).append('=').append(value.getMaxAge());
         }
         if (value.getPath() != null) {
-            sb.append(';').append(PATH).append('=').append(maybeQuote(value.getPath()));
+            sb.append(';').append(PATH).append('=').append(maybeQuotePath(value.getPath()));
         }
         if (value.getExpiry() != null) {
             sb.append(';').append(EXPIRES).append('=').append(HttpUtils.toHttpDate(value.getExpiry()));
@@ -142,20 +144,24 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
      * @param value
      * @return String
      */
-    static String maybeQuote(String value) {
-        
-        StringBuilder buff = new StringBuilder();
-        // handle a null value as well as an empty one, attr=
-        if (null == value || 0 == value.length()) {
-            buff.append("");
-        } else if (needsQuote(value)) {
+    static String maybeQuote(String tSpecials, String value) {
+        if (needsQuote(tSpecials, value)) {
+            StringBuilder buff = new StringBuilder();
             buff.append('"');
-            buff.append(value);
+            if (value != null) {
+                buff.append(value);
+            }
             buff.append('"');
+            return buff.toString();
         } else {
-            buff.append(value);
+            return value == null ? "" : value;
         }
-        return buff.toString();
+    }
+    static String maybeQuoteAll(String value) {
+        return maybeQuote(TSPECIALS_ALL, value);
+    }
+    static String maybeQuotePath(String value) {
+        return maybeQuote(TSPECIALS_PATH, value);
     }
 
     /**
@@ -165,7 +171,7 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
      * @param value
      * @return boolean
      */
-    static boolean needsQuote(String value) {
+    static boolean needsQuote(String tSpecials, String value) {
         if (null == value) {
             return true;
         }
@@ -180,7 +186,7 @@ public class NewCookieHeaderProvider implements HeaderDelegate<NewCookie>
{
 
         for (int i = 0; i < len; i++) {
             char c = value.charAt(i);
-            if (c < 0x20 || c >= 0x7f || TSPECIALS.indexOf(c) != -1) {
+            if (c < 0x20 || c >= 0x7f || tSpecials.indexOf(c) != -1) {
                 return true;
             }
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/f64ee3c2/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
index f04aac6..f34653d 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
@@ -136,5 +136,11 @@ public class NewCookieHeaderProviderTest extends Assert {
         assertEquals("foo=\"bar (space)<>[]\";Comment=\"comment@comment:,\";Domain=domain.com;Max-Age=2;"
                      + "Path=\"/path?path\";Secure;Version=1", c.toString());
     }
+    @Test
+    public void testToStringWithPathSlalshOnly() {
+        NewCookie c = new NewCookie("foo", "bar (space)<>[]", "/path", "domain.com",
"comment@comment:,", 2, true);
+        assertEquals("foo=\"bar (space)<>[]\";Comment=\"comment@comment:,\";Domain=domain.com;Max-Age=2;"
+                     + "Path=/path;Secure;Version=1", c.toString());
+    }
     
 }


Mime
View raw message