[Python-checkins] bpo-42066: CookieJar cookies should not be sorted (GH-22745)
rhettinger
webhook-mailer at python.org
Wed Apr 20 21:45:29 EDT 2022
https://github.com/python/cpython/commit/615b24c80b0bbbc7b70aa1e9c28f9c4463c8c1ed
commit: 615b24c80b0bbbc7b70aa1e9c28f9c4463c8c1ed
branch: main
author: Iman Kermani <55282537+IKermani at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2022-04-20T20:45:24-05:00
summary:
bpo-42066: CookieJar cookies should not be sorted (GH-22745)
files:
A Misc/NEWS.d/next/Library/2020-10-19-08-50-41.bpo-42066.DsB-R6.rst
M Lib/http/cookiejar.py
M Lib/test/test_http_cookiejar.py
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py
index 136a1f16ffe63d..f19a366496a21a 100644
--- a/Lib/http/cookiejar.py
+++ b/Lib/http/cookiejar.py
@@ -1224,14 +1224,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
diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py
index 126ce4fc83f0d1..ad2b121fdaf5a1 100644
--- a/Lib/test/test_http_cookiejar.py
+++ b/Lib/test/test_http_cookiejar.py
@@ -1293,11 +1293,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
diff --git a/Misc/NEWS.d/next/Library/2020-10-19-08-50-41.bpo-42066.DsB-R6.rst b/Misc/NEWS.d/next/Library/2020-10-19-08-50-41.bpo-42066.DsB-R6.rst
new file mode 100644
index 00000000000000..f3de85461fbc0d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-10-19-08-50-41.bpo-42066.DsB-R6.rst
@@ -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.
More information about the Python-checkins
mailing list