You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2020/04/17 09:14:29 UTC

[httpcomponents-client] branch master updated: HTTPCLIENT-2076: fix NPE in LaxExpiresHandler (#222)

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/master by this push:
     new 12ec6f1  HTTPCLIENT-2076: fix NPE in LaxExpiresHandler (#222)
12ec6f1 is described below

commit 12ec6f15ea30cfa8e7a1b59f143adde3b175fcaf
Author: heejeongkim <ap...@gmail.com>
AuthorDate: Fri Apr 17 18:14:21 2020 +0900

    HTTPCLIENT-2076: fix NPE in LaxExpiresHandler (#222)
---
 .../org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java | 4 ++++
 .../hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java  | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
index ea4ae56..c48be4f 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java
@@ -43,6 +43,7 @@ import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.message.ParserCursor;
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.TextUtils;
 
 /**
  * Cookie {@code expires} attribute handler conformant to the more relaxed interpretation
@@ -107,6 +108,9 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
     @Override
     public void parse(final SetCookie cookie, final String value) throws MalformedCookieException {
         Args.notNull(cookie, "Cookie");
+        if (TextUtils.isBlank(value)) {
+            return;
+        }
         final ParserCursor cursor = new ParserCursor(0, value.length());
         final StringBuilder content = new StringBuilder();
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java
index 4a9dd27..b120b61 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestLaxCookieAttribHandlers.java
@@ -115,6 +115,14 @@ public class TestLaxCookieAttribHandlers {
         Assert.assertEquals(0, c.get(Calendar.MILLISECOND));
     }
 
+    @Test
+    public void testParseExpiryInvalidTime0() throws Exception {
+        final BasicClientCookie cookie = new BasicClientCookie("name", "value");
+        final CookieAttributeHandler h = new LaxExpiresHandler();
+        h.parse(cookie, null);
+        Assert.assertNull(cookie.getExpiryDate());
+    }
+
     @Test(expected = MalformedCookieException.class)
     public void testParseExpiryInvalidTime1() throws Exception {
         final BasicClientCookie cookie = new BasicClientCookie("name", "value");