Skip to content

Commit 044097e

Browse files
authored
[java] handle getNamedCookie and deleteNamedCookie for empty strings (#15092)
1 parent a3d04b7 commit 044097e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

java/src/org/openqa/selenium/remote/RemoteWebDriver.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,9 @@ public void addCookie(Cookie cookie) {
869869

870870
@Override
871871
public void deleteCookieNamed(String name) {
872+
if (name == null || name.isBlank()) {
873+
throw new IllegalArgumentException("Cookie name cannot be empty");
874+
}
872875
execute(DriverCommand.DELETE_COOKIE(name));
873876
}
874877

@@ -927,6 +930,9 @@ public Set<Cookie> getCookies() {
927930

928931
@Override
929932
public Cookie getCookieNamed(String name) {
933+
if (name == null || name.isBlank()) {
934+
throw new IllegalArgumentException("Cookie name cannot be empty");
935+
}
930936
Set<Cookie> allCookies = getCookies();
931937
for (Cookie cookie : allCookies) {
932938
if (cookie.getName().equals(name)) {

java/test/org/openqa/selenium/CookieImplementationTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium;
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
2122
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2223
import static org.openqa.selenium.testing.drivers.Browser.ALL;
2324
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
@@ -503,6 +504,18 @@ public void testDeleteNotExistedCookie() {
503504
driver.manage().deleteCookieNamed(key);
504505
}
505506

507+
@Test
508+
public void testDeleteEmptyNamedCookie() {
509+
assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(""));
510+
assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(" "));
511+
}
512+
513+
@Test
514+
public void testGetEmptyNamedCookie() {
515+
assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(""));
516+
assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(" "));
517+
}
518+
506519
@Test
507520
@Ignore(value = ALL, reason = "Non W3C conformant")
508521
public void testShouldDeleteOneOfTheCookiesWithTheSameName() {

0 commit comments

Comments
 (0)