From 615b24c80b0bbbc7b70aa1e9c28f9c4463c8c1ed Mon Sep 17 00:00:00 2001 From: Iman Kermani <55282537+IKermani@users.noreply.github.com> Date: Thu, 21 Apr 2022 06:15:24 +0430 Subject: [PATCH] bpo-42066: CookieJar cookies should not be sorted (GH-22745) --- Lib/http/cookiejar.py | 9 ++------- Lib/test/test_http_cookiejar.py | 10 +++++----- .../Library/2020-10-19-08-50-41.bpo-42066.DsB-R6.rst | 2 ++ 3 files changed, 9 insertions(+), 12 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2020-10-19-08-50-41.bpo-42066.DsB-R6.rst 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.