Skip to content

Commit

Permalink
Fix cookies get_dict (#372)
Browse files Browse the repository at this point in the history
* Fix cookies get_dict

* Tests added
  • Loading branch information
the-laziest authored Aug 18, 2024
1 parent b0deb7b commit 2989ef5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion curl_cffi/requests/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def get_dict(self, domain: Optional[str] = None, path: Optional[str] = None) ->
"""
ret = {}
for cookie in self.jar:
if (domain is None or cookie.name == domain) and (path is None or cookie.path == path):
if (domain is None or cookie.domain == domain) and (path is None or cookie.path == path):
ret[cookie.name] = cookie.value
return ret

Expand Down
12 changes: 12 additions & 0 deletions tests/unittest/test_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,15 @@ def test_get_dict():
assert d["foo"] == "bar"
assert d["hello"] == "world"
assert d["a"] == "b"

c = Cookies()
c.set("foo", "bar", domain="example.com")
c.set("hello", "world", domain="example.com")
c.set("foo", "bar", domain="test.local")
d_example = c.get_dict("example.com")
d_test = c.get_dict("test.local")
assert len(d_example) == 2
assert d_example["foo"] == "bar"
assert d_example["hello"] == "world"
assert len(d_test) == 1
assert d_test["foo"] == "bar"

0 comments on commit 2989ef5

Please sign in to comment.