Skip to content

Commit 615b24c

Browse files
authored
bpo-42066: CookieJar cookies should not be sorted (GH-22745)
1 parent 031f1e6 commit 615b24c

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

Lib/http/cookiejar.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,14 +1224,9 @@ def path_return_ok(self, path, request):
12241224
_debug(" %s does not path-match %s", req_path, path)
12251225
return False
12261226

1227-
def vals_sorted_by_key(adict):
1228-
keys = sorted(adict.keys())
1229-
return map(adict.get, keys)
1230-
12311227
def deepvalues(mapping):
1232-
"""Iterates over nested mapping, depth-first, in sorted order by key."""
1233-
values = vals_sorted_by_key(mapping)
1234-
for obj in values:
1228+
"""Iterates over nested mapping, depth-first"""
1229+
for obj in list(mapping.values()):
12351230
mapping = False
12361231
try:
12371232
obj.items

Lib/test/test_http_cookiejar.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,11 +1293,11 @@ def test_Cookie_iterator(self):
12931293
r'port="90,100, 80,8080"; '
12941294
r'max-age=100; Comment = "Just kidding! (\"|\\\\) "')
12951295

1296-
versions = [1, 1, 1, 0, 1]
1297-
names = ["bang", "foo", "foo", "spam", "foo"]
1298-
domains = [".sol.no", "blah.spam.org", "www.acme.com",
1299-
"www.acme.com", "www.acme.com"]
1300-
paths = ["/", "/", "/", "/blah", "/blah/"]
1296+
versions = [1, 0, 1, 1, 1]
1297+
names = ["foo", "spam", "foo", "foo", "bang"]
1298+
domains = ["blah.spam.org", "www.acme.com", "www.acme.com",
1299+
"www.acme.com", ".sol.no"]
1300+
paths = ["/", "/blah", "/blah/", "/", "/"]
13011301

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

0 commit comments

Comments
 (0)