diff --git a/curl_cffi/requests/cookies.py b/curl_cffi/requests/cookies.py index d24b253..3963e41 100644 --- a/curl_cffi/requests/cookies.py +++ b/curl_cffi/requests/cookies.py @@ -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 diff --git a/tests/unittest/test_cookies.py b/tests/unittest/test_cookies.py index c24f115..2e50b1f 100644 --- a/tests/unittest/test_cookies.py +++ b/tests/unittest/test_cookies.py @@ -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"