Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions java/jakarta/servlet/http/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public String getPath() {
* @see #getSecure
*/
public void setSecure(boolean flag) {
setAttributeInternal(SECURE, EMPTY_STRING);
setAttributeInternal(SECURE, flag ? EMPTY_STRING : null);
}


Expand Down Expand Up @@ -349,7 +349,7 @@ public Object clone() {
* @since Servlet 3.0
*/
public void setHttpOnly(boolean httpOnly) {
setAttributeInternal(HTTP_ONLY, EMPTY_STRING);
setAttributeInternal(HTTP_ONLY, httpOnly ? EMPTY_STRING : null);
}


Expand Down
30 changes: 30 additions & 0 deletions test/jakarta/servlet/http/TestCookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public void testDefaults() {
Assert.assertNull(cookie.getValue());
Assert.assertEquals(0, cookie.getVersion());
Assert.assertEquals(-1, cookie.getMaxAge());
Assert.assertFalse(cookie.isHttpOnly());
Assert.assertFalse(cookie.getSecure());
}

@SuppressWarnings("removal")
Expand Down Expand Up @@ -145,6 +147,34 @@ public void testMaxAge01() {
}
}

@Test
public void testHttpOnlySet() {
Cookie cookie = new Cookie("name", "value");
cookie.setHttpOnly(true);
Assert.assertTrue(cookie.isHttpOnly());
}

@Test
public void testHttpOnlyUnset() {
Cookie cookie = new Cookie("name", "value");
cookie.setHttpOnly(false);
Assert.assertFalse(cookie.isHttpOnly());
}

@Test
public void testSecureSet() {
Cookie cookie = new Cookie("name", "value");
cookie.setSecure(true);
Assert.assertTrue(cookie.getSecure());
}

@Test
public void testSecureUnset() {
Cookie cookie = new Cookie("name", "value");
cookie.setSecure(false);
Assert.assertFalse(cookie.getSecure());
}

@Test
public void testAttribute01() {
Cookie cookie = new Cookie("name", "value");
Expand Down