mirror of
https://github.com/l1ving/youtube-dl
synced 2024-11-20 20:25:37 +08:00
[utils] Prevent hyphen at beginning of filename (Fixes #5035)
This commit is contained in:
parent
9c665ab72e
commit
5a42414b9c
@ -85,6 +85,8 @@ class TestUtil(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sanitize_filename('New World record at 0:12:34'),
|
sanitize_filename('New World record at 0:12:34'),
|
||||||
'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\\/'
|
forbidden = '"\0\\/'
|
||||||
for fc in forbidden:
|
for fc in forbidden:
|
||||||
|
@ -304,6 +304,8 @@ def sanitize_filename(s, restricted=False, is_id=False):
|
|||||||
# Common case of "Foreign band name - English song title"
|
# Common case of "Foreign band name - English song title"
|
||||||
if restricted and result.startswith('-_'):
|
if restricted and result.startswith('-_'):
|
||||||
result = result[2:]
|
result = result[2:]
|
||||||
|
if result.startswith('-'):
|
||||||
|
result = '_' + result[len('-'):]
|
||||||
if not result:
|
if not result:
|
||||||
result = '_'
|
result = '_'
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user