File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
src/org/openqa/selenium/remote Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -869,6 +869,9 @@ public void addCookie(Cookie cookie) {
869869
870870 @ Override
871871 public void deleteCookieNamed (String name ) {
872+ if (name .isEmpty () || name .equals (" " )) {
873+ throw new IllegalArgumentException ("Cookie name cannot be empty or null" );
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 .isEmpty () || name .equals (" " )) {
934+ throw new IllegalArgumentException ("Cookie name cannot be empty or null" );
935+ }
930936 Set <Cookie > allCookies = getCookies ();
931937 for (Cookie cookie : allCookies ) {
932938 if (cookie .getName ().equals (name )) {
Original file line number Diff line number Diff line change 1818package org .openqa .selenium ;
1919
2020import static org .assertj .core .api .Assertions .assertThat ;
21+ import static org .junit .jupiter .api .Assertions .assertThrows ;
2122import static org .junit .jupiter .api .Assumptions .assumeTrue ;
2223import static org .openqa .selenium .testing .drivers .Browser .ALL ;
2324import 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 () {
You can’t perform that action at this time.
0 commit comments