Skip to content
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

gh-87888: Make FileCookieJar use ASCII/surrogateescape #92392

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,9 @@ def load(self, filename=None, ignore_discard=False, ignore_expires=False):
if self.filename is not None: filename = self.filename
else: raise ValueError(MISSING_FILENAME_TEXT)

with open(filename) as f:
# We use latin-1 here because WSGI uses latin-1 for HTTP headers too.
# See gh-87888 for more info.
with open(filename, encoding="latin1") as f:
self._really_load(f, filename, ignore_discard, ignore_expires)

def revert(self, filename=None,
Expand Down Expand Up @@ -1890,7 +1892,7 @@ def save(self, filename=None, ignore_discard=False, ignore_expires=False):
if self.filename is not None: filename = self.filename
else: raise ValueError(MISSING_FILENAME_TEXT)

with open(filename, "w") as f:
with open(filename, "w", encoding="latin1") as f:
# There really isn't an LWP Cookies 2.0 format, but this indicates
# that there is extra information in here (domain_dot and
# port_spec) while still being compatible with libwww-perl, I hope.
Expand Down Expand Up @@ -2086,7 +2088,7 @@ def save(self, filename=None, ignore_discard=False, ignore_expires=False):
if self.filename is not None: filename = self.filename
else: raise ValueError(MISSING_FILENAME_TEXT)

with open(filename, "w") as f:
with open(filename, "w", encoding="latin1") as f:
f.write(NETSCAPE_HEADER_TEXT)
now = time.time()
for cookie in self:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Changed encoding used by :class:`http.cookiejar.FileCookieJar` and its
subclasses from locale encoding to "latin-1".