hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1530218 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java httpclient/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java
Date Tue, 08 Oct 2013 10:36:31 GMT
Author: olegk
Date: Tue Oct  8 10:36:30 2013
New Revision: 1530218

URL: http://svn.apache.org/r1530218
Log:
HTTPCLIENT-1417: Fixed NPE in BrowserCompatSpec#formatCookies caused by version 1 cookies
with null cookie value

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    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

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1530218&r1=1530217&r2=1530218&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Tue Oct  8 10:36:30 2013
@@ -1,6 +1,10 @@
-Changes sicne 4.3.1
+Changes since 4.3.1
 -------------------
 
+* [HTTPCLIENT-1417] Fixed NPE in BrowserCompatSpec#formatCookies caused by version 1
+  cookies with null cookie value.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1416] Fixed NPE in CachingHttpClientBuilder#build().
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

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=1530218&r1=1530217&r2=1530218&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 Oct  8 10:36:30 2013
@@ -168,6 +168,10 @@ public class BrowserCompatSpec extends C
         return parse(helems, origin);
     }
 
+    private static boolean isQuoteEnclosed(final String s) {
+        return s != null && s.startsWith("\"") && s.endsWith("\"");
+    }
+
     public List<Header> formatCookies(final List<Cookie> cookies) {
         Args.notEmpty(cookies, "List of cookies");
         final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
@@ -180,8 +184,7 @@ public class BrowserCompatSpec extends C
             }
             final String cookieName = cookie.getName();
             final String cookieValue = cookie.getValue();
-            if (cookie.getVersion() > 0 &&
-                    !(cookieValue.startsWith("\"") && cookieValue.endsWith("\"")))
{
+            if (cookie.getVersion() > 0 && !isQuoteEnclosed(cookieValue)) {
                 BasicHeaderValueFormatter.INSTANCE.formatHeaderElement(
                         buffer,
                         new BasicHeaderElement(cookieName, 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=1530218&r1=1530217&r2=1530218&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 Oct  8 10:36:30 2013
@@ -922,6 +922,24 @@ public class TestBrowserCompatSpec {
         Assert.assertEquals("name=", headers.get(0).getValue());
     }
 
+    @Test
+    public void testNullCookieValueFormattingCookieVersion1() {
+        final BasicClientCookie cookie = new BasicClientCookie("name", null);
+        cookie.setVersion(1);
+        cookie.setDomain(".whatever.com");
+        cookie.setAttribute(ClientCookie.DOMAIN_ATTR, cookie.getDomain());
+        cookie.setPath("/");
+        cookie.setAttribute(ClientCookie.PATH_ATTR, cookie.getPath());
+
+        final CookieSpec cookiespec = new BrowserCompatSpec();
+        final List<Cookie> cookies = new ArrayList<Cookie>(1);
+        cookies.add(cookie);
+        final List<Header> headers = cookiespec.formatCookies(cookies);
+        Assert.assertNotNull(headers);
+        Assert.assertEquals(1, headers.size());
+        Assert.assertEquals("name", headers.get(0).getValue());
+    }
+
     /**
      * Tests generic cookie formatting.
      */



Mime
View raw message