Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ Patches and Suggestions
- Dave Shawley <[email protected]>
- James Clarke (`@jam <https://github.com/jam>`_)
- Kevin Burke <[email protected]>
- Flavio Curella
- David Pursehouse <[email protected]> (`@dpursehouse <https://github.com/dpursehouse>`_)
- Jon Parise (`@jparise <https://github.com/jparise>`_)
- Alexander Karpinsky (`@homm86 <https://twitter.com/homm86>`_)
Expand Down Expand Up @@ -193,3 +192,4 @@ Patches and Suggestions
- Sylvain Marié (`@smarie <https://github.com/smarie>`_)
- Hod Bin Noon (`@hodbn <https://github.com/hodbn>`_)
- Mike Fiedler (`@miketheman <https://github.com/miketheman>`_)
- Linkai Zheng (`@Konano <https://github.com/Konano>`_)
9 changes: 0 additions & 9 deletions src/requests/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 17 additions & 2 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down