|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 |
|
18 | | -from typing import Optional, Union |
| 18 | +from typing import Any, Optional, Union |
19 | 19 |
|
20 | 20 | from selenium.webdriver.common.bidi.common import command_builder |
21 | 21 |
|
@@ -85,12 +85,19 @@ def from_dict(cls, data: dict) -> "Cookie": |
85 | 85 | ------- |
86 | 86 | Cookie: A new instance of Cookie. |
87 | 87 | """ |
88 | | - value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value")) |
| 88 | + # Validation for empty strings |
| 89 | + name = data.get("name") |
| 90 | + if not name: |
| 91 | + raise ValueError("name is required and cannot be empty") |
| 92 | + domain = data.get("domain") |
| 93 | + if not domain: |
| 94 | + raise ValueError("domain is required and cannot be empty") |
89 | 95 |
|
| 96 | + value = BytesValue(data.get("value", {}).get("type"), data.get("value", {}).get("value")) |
90 | 97 | return cls( |
91 | | - name=data.get("name"), |
| 98 | + name=str(name), |
92 | 99 | value=value, |
93 | | - domain=data.get("domain"), |
| 100 | + domain=str(domain), |
94 | 101 | path=data.get("path"), |
95 | 102 | size=data.get("size"), |
96 | 103 | http_only=data.get("httpOnly"), |
@@ -125,14 +132,14 @@ def __init__( |
125 | 132 | self.same_site = same_site |
126 | 133 | self.expiry = expiry |
127 | 134 |
|
128 | | - def to_dict(self) -> dict: |
| 135 | + def to_dict(self) -> dict[str, Any]: |
129 | 136 | """Converts the CookieFilter to a dictionary. |
130 | 137 |
|
131 | 138 | Returns: |
132 | 139 | ------- |
133 | 140 | Dict: A dictionary representation of the CookieFilter. |
134 | 141 | """ |
135 | | - result = {} |
| 142 | + result: dict[str, Any] = {} |
136 | 143 | if self.name is not None: |
137 | 144 | result["name"] = self.name |
138 | 145 | if self.value is not None: |
@@ -242,14 +249,14 @@ def __init__( |
242 | 249 | self.same_site = same_site |
243 | 250 | self.expiry = expiry |
244 | 251 |
|
245 | | - def to_dict(self) -> dict: |
| 252 | + def to_dict(self) -> dict[str, Any]: |
246 | 253 | """Converts the PartialCookie to a dictionary. |
247 | 254 |
|
248 | 255 | Returns: |
249 | 256 | ------- |
250 | 257 | Dict: A dictionary representation of the PartialCookie. |
251 | 258 | """ |
252 | | - result = { |
| 259 | + result: dict[str, Any] = { |
253 | 260 | "name": self.name, |
254 | 261 | "value": self.value.to_dict(), |
255 | 262 | "domain": self.domain, |
|
0 commit comments