Skip to content

Commit e56a4fd

Browse files
bdracoasvetlov
andauthored
[PR #3753/401c256 backport][3.11] Enforce URL for cookie_jar.filter_cookies() call (#9715)
Co-authored-by: Andrew Svetlov <[email protected]>
1 parent 5914dc5 commit e56a4fd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

aiohttp/cookiejar.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pickle
1010
import re
1111
import time
12+
import warnings
1213
from collections import defaultdict
1314
from http.cookies import BaseCookie, Morsel, SimpleCookie
1415
from typing import (
@@ -309,7 +310,14 @@ def filter_cookies(self, request_url: URL = URL()) -> "BaseCookie[str]":
309310
if not self._cookies:
310311
# Skip rest of function if no non-expired cookies.
311312
return filtered
312-
request_url = URL(request_url)
313+
if type(request_url) is not URL:
314+
warnings.warn(
315+
"filter_cookies expects yarl.URL instances only,"
316+
f"and will stop working in 4.x, got {type(request_url)}",
317+
DeprecationWarning,
318+
stacklevel=2,
319+
)
320+
request_url = URL(request_url)
313321
hostname = request_url.raw_host or ""
314322

315323
is_not_secure = request_url.scheme not in ("https", "wss")

tests/test_cookiejar.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ async def test_filter_cookies_with_domain_path_lookup_multilevelpath(
313313
assert c in expected_cookies
314314

315315

316+
async def test_filter_cookies_str_deprecated(loop: asyncio.AbstractEventLoop) -> None:
317+
jar = CookieJar()
318+
jar.update_cookies(SimpleCookie("shared-cookie=first; Domain=example.com;"))
319+
with pytest.warns(DeprecationWarning):
320+
jar.filter_cookies("http://éé.com")
321+
322+
316323
async def test_domain_filter_ip_cookie_send() -> None:
317324
jar = CookieJar()
318325
cookies = SimpleCookie(

0 commit comments

Comments
 (0)