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:19:09 UTC

[httpcomponents-client] branch 4.5.x 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 4.5.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/4.5.x by this push:
     new 32a5c09  HTTPCLIENT-2076: fix NPE in LaxExpiresHandler (#222)
32a5c09 is described below

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

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

diff --git a/httpclient/src/main/java/org/apache/http/impl/cookie/LaxExpiresHandler.java b/httpclient/src/main/java/org/apache/http/impl/cookie/LaxExpiresHandler.java
index 02fdbdc..4ed52de 100644
--- a/httpclient/src/main/java/org/apache/http/impl/cookie/LaxExpiresHandler.java
+++ b/httpclient/src/main/java/org/apache/http/impl/cookie/LaxExpiresHandler.java
@@ -43,6 +43,7 @@ import org.apache.http.cookie.MalformedCookieException;
 import org.apache.http.cookie.SetCookie;
 import org.apache.http.message.ParserCursor;
 import org.apache.http.util.Args;
+import org.apache.http.util.TextUtils;
 
 /**
  *
@@ -105,6 +106,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/httpclient/src/test/java/org/apache/http/impl/cookie/TestLaxCookieAttribHandlers.java b/httpclient/src/test/java/org/apache/http/impl/cookie/TestLaxCookieAttribHandlers.java
index d47d0ae..20bdbdd 100644
--- a/httpclient/src/test/java/org/apache/http/impl/cookie/TestLaxCookieAttribHandlers.java
+++ b/httpclient/src/test/java/org/apache/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");