hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1463513 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/impl/cookie/ test/java/org/apache/http/impl/cookie/
Date Tue, 02 Apr 2013 12:50:20 GMT
Author: olegk
Date: Tue Apr  2 12:50:19 2013
New Revision: 1463513

URL: http://svn.apache.org/r1463513
Log:
HTTPCLIENT-1327: BrowserCompatSpec double quotes cookie value when 'expires' attribute is
present

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2109Spec.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java?rev=1463513&r1=1463512&r2=1463513&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
Tue Apr  2 12:50:19 2013
@@ -154,18 +154,20 @@ public class BrowserCompatSpec extends C
             if (i > 0) {
                 buffer.append("; ");
             }
-            if (cookie.getVersion() > 0) {
+            final String cookieName = cookie.getName();
+            final String cookieValue = cookie.getValue();
+            if (cookie.getVersion() > 0 &&
+                    !(cookieValue.startsWith("\"") && cookieValue.endsWith("\"")))
{
                 BasicHeaderValueFormatter.INSTANCE.formatHeaderElement(
                         buffer,
-                        new BasicHeaderElement(cookie.getName(), cookie.getValue()),
+                        new BasicHeaderElement(cookieName, cookieValue),
                         false);
             } else {
                 // Netscape style cookies do not support quoted values
-                buffer.append(cookie.getName());
+                buffer.append(cookieName);
                 buffer.append("=");
-                final String s = cookie.getValue();
-                if (s != null) {
-                    buffer.append(s);
+                if (cookieValue != null) {
+                    buffer.append(cookieValue);
                 }
             }
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java?rev=1463513&r1=1463512&r2=1463513&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java
Tue Apr  2 12:50:19 2013
@@ -1032,4 +1032,22 @@ public class TestBrowserCompatSpec {
         Assert.assertEquals("test=value 1", headers.get(0).getValue());
     }
 
+    @Test
+    public void testVersion1CookieWithInvalidExpires() throws Exception {
+        final CookieSpec cookiespec = new BrowserCompatSpec();
+        final CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
+
+        final Header origHeader = new BasicHeader("Set-Cookie",
+            "test=\"test\"; Version=1; Expires=Mon, 11-Feb-2013 10:39:19 GMT; Path=/");
+        final List<Cookie> cookies = cookiespec.parse(origHeader, origin);
+        Assert.assertNotNull(cookies);
+        Assert.assertEquals(1, cookies.size());
+
+        final List<Header> headers = cookiespec.formatCookies(cookies);
+        Assert.assertNotNull(headers);
+        Assert.assertEquals(1, headers.size());
+        final Header header1 = headers.get(0);
+        Assert.assertEquals("test=\"test\"", header1.getValue());
+    }
+
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2109Spec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2109Spec.java?rev=1463513&r1=1463512&r2=1463513&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2109Spec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2109Spec.java
Tue Apr  2 12:50:19 2013
@@ -437,6 +437,16 @@ public class TestCookieRFC2109Spec {
                 "name4=value4; $Path=/", headers.get(0).getValue());
     }
 
+    @Test(expected=MalformedCookieException.class)
+    public void testVersion1CookieWithInvalidExpires() throws Exception {
+        final CookieSpec cookiespec = new RFC2109Spec();
+        final CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
+
+        final Header origHeader = new BasicHeader("Set-Cookie",
+            "test=\"test\"; Version=1; Expires=Mon, 11-Feb-2013 10:39:19 GMT; Path=/");
+        cookiespec.parse(origHeader, origin);
+    }
+
     @Test
     public void testInvalidInput() throws Exception {
         final CookieSpec cookiespec = new RFC2109Spec();



Mime
View raw message