Fixes NPE in ClientCookieDecoder

Motivation:
NPE in `ClientCookieDecoder` if cookie starts with comma.

Modifications:
Check `cookieBuilder` for `null` in the return.

Result:
No fails NPE on invalid cookies.
This commit is contained in:
Nikolay Fedorovskikh 2018-04-05 22:44:08 +05:00 committed by Norman Maurer
parent c58069f284
commit 587afddb27
2 changed files with 8 additions and 1 deletions

View File

@ -140,7 +140,7 @@ public final class ClientCookieDecoder extends CookieDecoder {
cookieBuilder.appendAttribute(nameBegin, nameEnd, valueBegin, valueEnd);
}
}
return cookieBuilder.cookie();
return cookieBuilder != null ? cookieBuilder.cookie() : null;
}
private static class CookieBuilder {

View File

@ -203,6 +203,13 @@ public class ClientCookieDecoderTest {
assertNull(cookie);
}
@Test
public void testDecodingInvalidValuesWithCommaAtStart() {
assertNull(ClientCookieDecoder.STRICT.decode(","));
assertNull(ClientCookieDecoder.STRICT.decode(",a"));
assertNull(ClientCookieDecoder.STRICT.decode(",a=a"));
}
@Test
public void testDecodingLongValue() {
String longValue =