From 3a14a8fb9f2aac551503d1dd047284a8d3cca5a9 Mon Sep 17 00:00:00 2001 From: Konano Date: Wed, 12 Feb 2025 01:14:12 +0800 Subject: [PATCH 1/4] test(cookies): add test for cookie with JSON value --- tests/test_requests.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index d8fbb23688..fcc5c08543 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -394,8 +394,23 @@ def test_cookie_removed_on_expire(self, httpbin): def test_cookie_quote_wrapped(self, httpbin): s = requests.session() - s.get(httpbin('cookies/set?foo="bar:baz"')) - assert s.cookies["foo"] == '"bar:baz"' + r = s.get(httpbin('cookies/set?foo="bar:baz"')) + assert s.cookies["foo"] == '"\\"bar:baz\\""' + assert r.request.headers["Cookie"] == 'foo="\\"bar:baz\\""' + assert r.json()["cookies"]["foo"] == '"bar:baz"' + + def test_cookie_with_json_value(self, httpbin): + s = requests.session() + r = s.get(httpbin('cookies/set?foo={"bar":"baz"}')) + assert s.cookies["foo"] == '"{\\"bar\\":\\"baz\\"}"' + assert r.request.headers["Cookie"] == 'foo="{\\"bar\\":\\"baz\\"}"' + assert r.json()["cookies"]["foo"] == '{"bar":"baz"}' + + def test_param_cookies_with_json_value(self, httpbin): + s = requests.session() + r = s.get(httpbin("cookies"), cookies={"foo": '"{\\"bar\\":\\"baz\\"}"'}) + assert r.request.headers["Cookie"] == 'foo="{\\"bar\\":\\"baz\\"}"' + assert r.json()["cookies"]["foo"] == '{"bar":"baz"}' def test_cookie_persists_via_api(self, httpbin): s = requests.session() From ecc61f028d34add0798abe73cdb82b505b14ef55 Mon Sep 17 00:00:00 2001 From: Konano Date: Wed, 12 Feb 2025 01:20:37 +0800 Subject: [PATCH 2/4] fix(cookies): remove useless and incorrect implementation --- src/requests/cookies.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/requests/cookies.py b/src/requests/cookies.py index f69d0cda9e..8e619bb0b3 100644 --- a/src/requests/cookies.py +++ b/src/requests/cookies.py @@ -346,15 +346,6 @@ def __delitem__(self, name): """ remove_cookie_by_name(self, name) - def set_cookie(self, cookie, *args, **kwargs): - if ( - hasattr(cookie.value, "startswith") - and cookie.value.startswith('"') - and cookie.value.endswith('"') - ): - cookie.value = cookie.value.replace('\\"', "") - return super().set_cookie(cookie, *args, **kwargs) - def update(self, other): """Updates this jar with cookies from another CookieJar or dict-like""" if isinstance(other, cookielib.CookieJar): From 434a36b3b8dc35446793764a8867330d20f5f3c7 Mon Sep 17 00:00:00 2001 From: Konano Date: Wed, 12 Feb 2025 01:34:53 +0800 Subject: [PATCH 3/4] chore(authors): add Linkai Zheng to the authors list --- AUTHORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 6e017c9a91..02d4413b6a 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -193,3 +193,4 @@ Patches and Suggestions - Sylvain MariƩ (`@smarie `_) - Hod Bin Noon (`@hodbn `_) - Mike Fiedler (`@miketheman `_) +- Linkai Zheng (`@Konano `_) From 7875ec3a57ead5088558d8f0f5c0a319037651d1 Mon Sep 17 00:00:00 2001 From: Konano Date: Wed, 12 Feb 2025 11:51:54 +0800 Subject: [PATCH 4/4] Revert PR 1440 --- AUTHORS.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 02d4413b6a..0080bfd75d 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -129,7 +129,6 @@ Patches and Suggestions - Dave Shawley - James Clarke (`@jam `_) - Kevin Burke -- Flavio Curella - David Pursehouse (`@dpursehouse `_) - Jon Parise (`@jparise `_) - Alexander Karpinsky (`@homm86 `_)