]> gitweb @ CieloNegro.org - youtube-dl.git/commitdiff
Revert "[utils] Add support for cookies with spaces used instead of tabs"
authorSergey M․ <dstftw@gmail.com>
Mon, 9 Mar 2020 21:51:20 +0000 (04:51 +0700)
committerSergey M․ <dstftw@gmail.com>
Mon, 9 Mar 2020 21:53:51 +0000 (04:53 +0700)
According to [1] TABs must be used as separators between fields.
Files produces by some tools with spaces as separators are considered
malformed.

1. https://curl.haxx.se/docs/http-cookies.html

This reverts commit cff99c91d150df2a4e21962a3ca8d4ae94533b8c.

test/test_YoutubeDLCookieJar.py
test/testdata/cookies/cookie_file_with_spaces.txt [deleted file]
youtube_dl/utils.py

index f833efac532fd4497305479470ab59a54ef675ac..f959798deb595165fddac6a8e555570c0420e454 100644 (file)
@@ -14,9 +14,6 @@ from youtube_dl.utils import YoutubeDLCookieJar
 
 
 class TestYoutubeDLCookieJar(unittest.TestCase):
-    def __assert_cookie_has_value(self, cookiejar, key):
-        self.assertEqual(cookiejar._cookies['www.foobar.foobar']['/'][key].value, key + '_VALUE')
-
     def test_keep_session_cookies(self):
         cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/session_cookies.txt')
         cookiejar.load(ignore_discard=True, ignore_expires=True)
@@ -35,13 +32,12 @@ class TestYoutubeDLCookieJar(unittest.TestCase):
     def test_strip_httponly_prefix(self):
         cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/httponly_cookies.txt')
         cookiejar.load(ignore_discard=True, ignore_expires=True)
-        self.__assert_cookie_has_value(cookiejar, 'HTTPONLY_COOKIE')
-        self.__assert_cookie_has_value(cookiejar, 'JS_ACCESSIBLE_COOKIE')
 
-    def test_convert_spaces_to_tabs(self):
-        cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/cookie_file_with_spaces.txt')
-        cookiejar.load(ignore_discard=True, ignore_expires=True)
-        self.__assert_cookie_has_value(cookiejar, 'COOKIE')
+        def assert_cookie_has_value(key):
+            self.assertEqual(cookiejar._cookies['www.foobar.foobar']['/'][key].value, key + '_VALUE')
+
+        assert_cookie_has_value('HTTPONLY_COOKIE')
+        assert_cookie_has_value('JS_ACCESSIBLE_COOKIE')
 
 
 if __name__ == '__main__':
diff --git a/test/testdata/cookies/cookie_file_with_spaces.txt b/test/testdata/cookies/cookie_file_with_spaces.txt
deleted file mode 100644 (file)
index 6fda35f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-# Netscape HTTP Cookie File
-# http://curl.haxx.se/rfc/cookie_spec.html
-# This is a generated file!  Do not edit.
-
-www.foobar.foobar     FALSE   /       TRUE    2147483647      COOKIE COOKIE_VALUE
index 93d1dec0506207d6974689af1b9257ef9541c224..8ccf254895133f38d1c8e095718a0d53d53bd061 100644 (file)
@@ -2752,11 +2752,6 @@ class YoutubeDLCookieJar(compat_cookiejar.MozillaCookieJar):
             for line in f:
                 if line.startswith(self._HTTPONLY_PREFIX):
                     line = line[len(self._HTTPONLY_PREFIX):]
-                # Cookie file may contain spaces instead of tabs.
-                # Replace all spaces with tabs to make such cookie files work
-                # with MozillaCookieJar.
-                if not line.startswith('#'):
-                    line = re.sub(r' +', r'\t', line)
                 cf.write(compat_str(line))
         cf.seek(0)
         self._really_load(cf, filename, ignore_discard, ignore_expires)