From: Sergey M․ Date: Mon, 9 Mar 2015 18:50:11 +0000 (+0600) Subject: [utils] Keep dot and dotdot unmodified (Closes #5171) X-Git-Url: http://git.oshgnacknak.de/?a=commitdiff_plain;h=2ebfeacabc7b74d03fa7cb096d8b9d1ecbdbb6e4;p=youtube-dl [utils] Keep dot and dotdot unmodified (Closes #5171) --- diff --git a/test/test_utils.py b/test/test_utils.py index 28bda654e..8f790bf0a 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -163,6 +163,11 @@ class TestUtil(unittest.TestCase): self.assertEqual(sanitize_path('abc.../def'), 'abc..#\\def') self.assertEqual(sanitize_path('abc.../def...'), 'abc..#\\def..#') + self.assertEqual(sanitize_path('../abc'), '..\\abc') + self.assertEqual(sanitize_path('../../abc'), '..\\..\\abc') + self.assertEqual(sanitize_path('./abc'), 'abc') + self.assertEqual(sanitize_path('./../abc'), '..\\abc') + def test_ordered_set(self): self.assertEqual(orderedSet([1, 1, 2, 3, 4, 4, 5, 6, 7, 3, 5]), [1, 2, 3, 4, 5, 6, 7]) self.assertEqual(orderedSet([]), []) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index d5597d514..c3135effc 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -319,7 +319,7 @@ def sanitize_path(s): if unc_or_drive: norm_path.pop(0) sanitized_path = [ - re.sub('(?:[/<>:"\\|\\\\?\\*]|\.$)', '#', path_part) + path_part if path_part in ['.', '..'] else re.sub('(?:[/<>:"\\|\\\\?\\*]|\.$)', '#', path_part) for path_part in norm_path] if unc_or_drive: sanitized_path.insert(0, unc_or_drive + os.path.sep)