fix loading/storing cookies without domain

pull/2432/head
Mike Fährmann 3 years ago
parent 500a479026
commit 8295bc6d97
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -289,12 +289,12 @@ def load_cookiestxt(fp):
for line in fp:
line = line.lstrip()
line = line.lstrip(" ")
# strip '#HttpOnly_'
if line.startswith("#HttpOnly_"):
line = line[10:]
# ignore empty lines and comments
if not line or line[0] in ("#", "$"):
if not line or line[0] in ("#", "$", "\n"):
continue
# strip trailing '\n'
if line[-1] == "\n":
@ -326,6 +326,9 @@ def save_cookiestxt(fp, cookies):
fp.write("# Netscape HTTP Cookie File\n\n")
for cookie in cookies:
if not cookie.domain:
continue
if cookie.value is None:
name = ""
value = cookie.name

@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2015-2021 Mike Fährmann
# Copyright 2015-2022 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@ -188,6 +188,10 @@ class TestCookiesTxt(unittest.TestCase):
".example.org\tTRUE\t/\tTRUE\t\tname\t",
[self._cookie("name", "", ".example.org")],
)
_assert(
"\tTRUE\t/\tTRUE\t\tname\t",
[self._cookie("name", "", "")],
)
_assert(
"# Netscape HTTP Cookie File\n"
"\n"
@ -241,6 +245,8 @@ class TestCookiesTxt(unittest.TestCase):
"n4", "" , "www.example.org", False, "/", False),
self._cookie(
"n5", "v5", "www.example.org", False, "/path", False, 100),
self._cookie(
"n6", "v6", "", False),
],
"# Netscape HTTP Cookie File\n"
"\n"

Loading…
Cancel
Save