diff --git a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java index 989b932125a3a..332faa86d4c25 100644 --- a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java +++ b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java @@ -869,6 +869,9 @@ public void addCookie(Cookie cookie) { @Override public void deleteCookieNamed(String name) { + if (name == null || name.isBlank()) { + throw new IllegalArgumentException("Cookie name cannot be empty"); + } execute(DriverCommand.DELETE_COOKIE(name)); } @@ -927,6 +930,9 @@ public Set getCookies() { @Override public Cookie getCookieNamed(String name) { + if (name == null || name.isBlank()) { + throw new IllegalArgumentException("Cookie name cannot be empty"); + } Set allCookies = getCookies(); for (Cookie cookie : allCookies) { if (cookie.getName().equals(name)) { diff --git a/java/test/org/openqa/selenium/CookieImplementationTest.java b/java/test/org/openqa/selenium/CookieImplementationTest.java index 5da0b5f408991..148247a79113e 100644 --- a/java/test/org/openqa/selenium/CookieImplementationTest.java +++ b/java/test/org/openqa/selenium/CookieImplementationTest.java @@ -18,6 +18,7 @@ package org.openqa.selenium; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.openqa.selenium.testing.drivers.Browser.ALL; import static org.openqa.selenium.testing.drivers.Browser.CHROME; @@ -503,6 +504,18 @@ public void testDeleteNotExistedCookie() { driver.manage().deleteCookieNamed(key); } + @Test + public void testDeleteEmptyNamedCookie() { + assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed("")); + assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(" ")); + } + + @Test + public void testGetEmptyNamedCookie() { + assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed("")); + assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(" ")); + } + @Test @Ignore(value = ALL, reason = "Non W3C conformant") public void testShouldDeleteOneOfTheCookiesWithTheSameName() {