Skip to content

bpo-42066: CookieJar cookies should not be sorted #22745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
9 changes: 2 additions & 7 deletions Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,14 +1216,9 @@ def path_return_ok(self, path, request):
_debug(" %s does not path-match %s", req_path, path)
return False

def vals_sorted_by_key(adict):
keys = sorted(adict.keys())
return map(adict.get, keys)

def deepvalues(mapping):
"""Iterates over nested mapping, depth-first, in sorted order by key."""
values = vals_sorted_by_key(mapping)
for obj in values:
"""Iterates over nested mapping, depth-first"""
for obj in list(mapping.values()):
mapping = False
try:
obj.items
Expand Down
10 changes: 5 additions & 5 deletions Lib/test/test_http_cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,11 +1251,11 @@ def test_Cookie_iterator(self):
r'port="90,100, 80,8080"; '
r'max-age=100; Comment = "Just kidding! (\"|\\\\) "')

versions = [1, 1, 1, 0, 1]
names = ["bang", "foo", "foo", "spam", "foo"]
domains = [".sol.no", "blah.spam.org", "www.acme.com",
"www.acme.com", "www.acme.com"]
paths = ["/", "/", "/", "/blah", "/blah/"]
versions = [1, 0, 1, 1, 1]
names = ["foo", "spam", "foo", "foo", "bang"]
domains = ["blah.spam.org", "www.acme.com", "www.acme.com",
"www.acme.com", ".sol.no"]
paths = ["/", "/blah", "/blah/", "/", "/"]

for i in range(4):
i = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix cookies getting sorted in :func:`CookieJar.__iter__` which is an extra behavior and not mentioned in RFC 2965 or Netscape cookie protocol.
Now the cookies in ``CookieJar`` follows the order of the ``Set-Cookie`` header. Patch by Iman Kermani.