diff --git a/src/main/java/com/inversoft/http/Cookie.java b/src/main/java/com/inversoft/http/Cookie.java index 8e275f1..fbec6e7 100644 --- a/src/main/java/com/inversoft/http/Cookie.java +++ b/src/main/java/com/inversoft/http/Cookie.java @@ -175,7 +175,9 @@ public static Cookie fromResponseHeader(String header) { } if (inAttributes) { - cookie.addAttribute(name, value); + if(name != null) { + cookie.addAttribute(name, value); + } } else { if (name == null || value == null || name.trim().length() == 0) { return null; diff --git a/src/test/java/com/inversoft/http/CookieTest.java b/src/test/java/com/inversoft/http/CookieTest.java index 627807e..1694441 100644 --- a/src/test/java/com/inversoft/http/CookieTest.java +++ b/src/test/java/com/inversoft/http/CookieTest.java @@ -179,6 +179,18 @@ public void fromResponseHeader() { // Borked cookie cookie = Cookie.fromResponseHeader("=a"); assertNull(cookie); + + // Cookie end with semicolon + cookie = Cookie.fromResponseHeader("foo=%2Fbar; Path=/; Secure; HTTPonly;"); + assertNull(cookie.domain); + assertNull(cookie.expires); + assertTrue(cookie.httpOnly); + assertNull(cookie.maxAge); + assertEquals(cookie.name, "foo"); + assertEquals(cookie.path, "/"); + assertNull(cookie.sameSite); + assertTrue(cookie.secure); + assertEquals(cookie.value, "%2Fbar"); } @Test