mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
fix loading/storing cookies without domain
This commit is contained in:
parent
500a479026
commit
8295bc6d97
@ -289,12 +289,12 @@ def load_cookiestxt(fp):
|
|||||||
|
|
||||||
for line in fp:
|
for line in fp:
|
||||||
|
|
||||||
line = line.lstrip()
|
line = line.lstrip(" ")
|
||||||
# strip '#HttpOnly_'
|
# strip '#HttpOnly_'
|
||||||
if line.startswith("#HttpOnly_"):
|
if line.startswith("#HttpOnly_"):
|
||||||
line = line[10:]
|
line = line[10:]
|
||||||
# ignore empty lines and comments
|
# ignore empty lines and comments
|
||||||
if not line or line[0] in ("#", "$"):
|
if not line or line[0] in ("#", "$", "\n"):
|
||||||
continue
|
continue
|
||||||
# strip trailing '\n'
|
# strip trailing '\n'
|
||||||
if line[-1] == "\n":
|
if line[-1] == "\n":
|
||||||
@ -326,6 +326,9 @@ def save_cookiestxt(fp, cookies):
|
|||||||
fp.write("# Netscape HTTP Cookie File\n\n")
|
fp.write("# Netscape HTTP Cookie File\n\n")
|
||||||
|
|
||||||
for cookie in cookies:
|
for cookie in cookies:
|
||||||
|
if not cookie.domain:
|
||||||
|
continue
|
||||||
|
|
||||||
if cookie.value is None:
|
if cookie.value is None:
|
||||||
name = ""
|
name = ""
|
||||||
value = cookie.name
|
value = cookie.name
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- 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
|
# 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
|
# 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",
|
".example.org\tTRUE\t/\tTRUE\t\tname\t",
|
||||||
[self._cookie("name", "", ".example.org")],
|
[self._cookie("name", "", ".example.org")],
|
||||||
)
|
)
|
||||||
|
_assert(
|
||||||
|
"\tTRUE\t/\tTRUE\t\tname\t",
|
||||||
|
[self._cookie("name", "", "")],
|
||||||
|
)
|
||||||
_assert(
|
_assert(
|
||||||
"# Netscape HTTP Cookie File\n"
|
"# Netscape HTTP Cookie File\n"
|
||||||
"\n"
|
"\n"
|
||||||
@ -241,6 +245,8 @@ class TestCookiesTxt(unittest.TestCase):
|
|||||||
"n4", "" , "www.example.org", False, "/", False),
|
"n4", "" , "www.example.org", False, "/", False),
|
||||||
self._cookie(
|
self._cookie(
|
||||||
"n5", "v5", "www.example.org", False, "/path", False, 100),
|
"n5", "v5", "www.example.org", False, "/path", False, 100),
|
||||||
|
self._cookie(
|
||||||
|
"n6", "v6", "", False),
|
||||||
],
|
],
|
||||||
"# Netscape HTTP Cookie File\n"
|
"# Netscape HTTP Cookie File\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user