diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 92d16200..e28ca861 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -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 diff --git a/test/test_util.py b/test/test_util.py index ce403a8e..9b0045c8 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -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"