HTTPCLIENT-2076: fix NPE in LaxExpiresHandler (#222)
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.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 @@
@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 @@
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");