diff --git a/AUTHORS.rst b/AUTHORS.rst index 96a3d49f..6267ddf0 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -131,3 +131,4 @@ Patches and Suggestions - Dave Shawley - James Clarke (jam) - Kevin Burke +- Flavio Curella diff --git a/requests/cookies.py b/requests/cookies.py index d62f0cd1..d1e5d75b 100644 --- a/requests/cookies.py +++ b/requests/cookies.py @@ -259,6 +259,11 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping): """Deletes a cookie given a name. Wraps cookielib.CookieJar's remove_cookie_by_name().""" remove_cookie_by_name(self, name) + def set_cookie(self, cookie, *args, **kwargs): + if cookie.value.startswith('"') and cookie.value.endswith('"'): + cookie.value = cookie.value.replace('\\"', '') + return super(RequestsCookieJar, self).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): diff --git a/test_requests.py b/test_requests.py index 07582105..f2b633b5 100755 --- a/test_requests.py +++ b/test_requests.py @@ -170,6 +170,11 @@ class RequestsTestCase(unittest.TestCase): ) assert 'foo' not in s.cookies + def test_cookie_quote_wrapped(self): + s = requests.session() + s.get(httpbin('cookies/set?foo="bar:baz"')) + self.assertTrue(s.cookies['foo'] == '"bar:baz"') + def test_request_cookie_overrides_session_cookie(self): s = requests.session() s.cookies['foo'] = 'bar'