Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def _debug(*args):
HTTPONLY_ATTR = "HTTPOnly"
HTTPONLY_PREFIX = "#HttpOnly_"
DEFAULT_HTTP_PORT = str(http.client.HTTP_PORT)
NETSCAPE_MAGIC_RGX = re.compile("#( Netscape)? HTTP Cookie File")
NETSCAPE_MAGIC_RGX = re.compile("#( Netscape)? HTTP Cookie File",
re.IGNORECASE | re.ASCII)
MISSING_FILENAME_TEXT = ("a filename was not supplied (nor was the CookieJar "
"instance initialised with one)")
NETSCAPE_HEADER_TEXT = """\
Expand Down
25 changes: 25 additions & 0 deletions Lib/test/test_http_cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,31 @@ def test_bad_magic(self):
finally:
os_helper.unlink(filename)

def test_magic_ignores_case(self):
filename = os_helper.TESTFN
self.addCleanup(os_helper.unlink, filename)
for magic in ("# Netscape HTTP Cookie File",
"# netscape http cookie file",
"# HTTP Cookie File",
"# http cookie file"):
with self.subTest(magic=magic):
with open(filename, "w") as f:
f.write(magic + "\n")
MozillaCookieJar().load(filename)

def test_magic_is_not_unicode(self):
# Unicode case folding must not be used: 'ſ' (U+017F) and 'K'
# (U+212A) are case-insensitively equal to 's' and 'k' in Unicode.
filename = os_helper.TESTFN
self.addCleanup(os_helper.unlink, filename)
for magic in ("# Netſcape HTTP Cookie File",
"# Netscape HTTP CooKie File"):
with self.subTest(magic=magic):
with open(filename, "w", encoding="utf-8") as f:
f.write(magic + "\n")
self.assertRaises(LoadError, MozillaCookieJar().load, filename)


class CookieTests(unittest.TestCase):
# XXX
# Get rid of string comparisons where not actually testing str / repr.
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ Brian Harring
Jonathan Hartley
Travis B. Hartwell
Henrik Harutyunyan
Ashley Harvey
Shane Harvey
Larry Hastings
Tim Hatch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:meth:`http.cookiejar.FileCookieJar.load` now checks the first, format
signature line in a case-insensitive manner. Patch by Ashley Harvey.
Loading