HTTPCLIENT-2076: fix NPE in LaxExpiresHandler (#222)

This commit is contained in:
heejeongkim 2020-04-17 18:14:21 +09:00 committed by GitHub
parent 3e484c0830
commit 12ec6f15ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -43,6 +43,7 @@ import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.message.ParserCursor; import org.apache.hc.core5.http.message.ParserCursor;
import org.apache.hc.core5.util.Args; 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 * Cookie {@code expires} attribute handler conformant to the more relaxed interpretation
@ -107,6 +108,9 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
@Override @Override
public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { public void parse(final SetCookie cookie, final String value) throws MalformedCookieException {
Args.notNull(cookie, "Cookie"); Args.notNull(cookie, "Cookie");
if (TextUtils.isBlank(value)) {
return;
}
final ParserCursor cursor = new ParserCursor(0, value.length()); final ParserCursor cursor = new ParserCursor(0, value.length());
final StringBuilder content = new StringBuilder(); final StringBuilder content = new StringBuilder();

View File

@ -115,6 +115,14 @@ public class TestLaxCookieAttribHandlers {
Assert.assertEquals(0, c.get(Calendar.MILLISECOND)); 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) @Test(expected = MalformedCookieException.class)
public void testParseExpiryInvalidTime1() throws Exception { public void testParseExpiryInvalidTime1() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value"); final BasicClientCookie cookie = new BasicClientCookie("name", "value");