瀏覽代碼

[utils] Prevent hyphen at beginning of filename (Fixes #5035)

Philipp Hagemeister 10 年之前
父節點
當前提交
5a42414b9c
共有 2 個文件被更改,包括 4 次插入0 次删除
  1. 2 0
      test/test_utils.py
  2. 2 0
      youtube_dl/utils.py

+ 2 - 0
test/test_utils.py

@@ -85,6 +85,8 @@ 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')
 
         forbidden = '"\0\\/'
         for fc in forbidden:

+ 2 - 0
youtube_dl/utils.py

@@ -304,6 +304,8 @@ def sanitize_filename(s, restricted=False, is_id=False):
         # Common case of "Foreign band name - English song title"
         if restricted and result.startswith('-_'):
             result = result[2:]
+        if result.startswith('-'):
+            result = '_' + result[len('-'):]
         if not result:
             result = '_'
     return result