]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42066: CookieJar cookies should not be sorted (GH-22745)
authorIman Kermani <55282537+IKermani@users.noreply.github.com>
Thu, 21 Apr 2022 01:45:24 +0000 (06:15 +0430)
committerGitHub <noreply@github.com>
Thu, 21 Apr 2022 01:45:24 +0000 (20:45 -0500)
Lib/http/cookiejar.py
Lib/test/test_http_cookiejar.py
Misc/NEWS.d/next/Library/2020-10-19-08-50-41.bpo-42066.DsB-R6.rst [new file with mode: 0644]

index 136a1f16ffe63d1187d489e986ba478be447f358..f19a366496a21a59830a0dac181dfcf8af305450 100644 (file)
@@ -1224,14 +1224,9 @@ class DefaultCookiePolicy(CookiePolicy):
         _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
index 126ce4fc83f0d1ccc6e1b74de10d0c5f6fd2ac29..ad2b121fdaf5a1a4ef667edc9fddc63a8e40a7c7 100644 (file)
@@ -1293,11 +1293,11 @@ class CookieTests(unittest.TestCase):
                       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 (file)
index 0000000..f3de854
--- /dev/null
@@ -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.\r
+Now the cookies in ``CookieJar`` follows the order of the ``Set-Cookie`` header. Patch by Iman Kermani.\r