From a7440261c52d6518a429210aaae598095112c61b Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Mon, 2 Mar 2015 19:07:17 +0100 Subject: [PATCH] [utils] Streap leading dots Fixes #2865, closes #5087 --- test/test_utils.py | 3 +++ youtube_dl/utils.py | 1 + 2 files changed, 4 insertions(+) diff --git a/test/test_utils.py b/test/test_utils.py index 3fba8ae11..64fad58ad 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -85,8 +85,11 @@ class TestUtil(unittest.TestCase): self.assertEqual( sanitize_filename('New World record at 0:12:34'), 'New World record at 0_12_34') + self.assertEqual(sanitize_filename('--gasdgf'), '_-gasdgf') self.assertEqual(sanitize_filename('--gasdgf', is_id=True), '--gasdgf') + self.assertEqual(sanitize_filename('.gasdgf'), 'gasdgf') + self.assertEqual(sanitize_filename('.gasdgf', is_id=True), '.gasdgf') forbidden = '"\0\\/' for fc in forbidden: diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index d4938ec36..1d3401bc2 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -305,6 +305,7 @@ def sanitize_filename(s, restricted=False, is_id=False): result = result[2:] if result.startswith('-'): result = '_' + result[len('-'):] + result = result.lstrip('.') if not result: result = '_' return result -- 2.40.0