From 87ea7dfc04a63a4ef80786ade1f0de93c6fe7fcd Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sun, 6 Jun 2021 19:30:21 +0530 Subject: [PATCH] Fix filename sanitization Bug from 752cda3880f30a46bed1d27b69188ab93ad1a368 --- test/test_YoutubeDL.py | 4 ++++ yt_dlp/YoutubeDL.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index 48015f98b..30c48c78f 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -655,6 +655,7 @@ class TestYoutubeDL(unittest.TestCase): 'height': 1080, 'title1': '$PATH', 'title2': '%PATH%', + 'title3': 'foo/bar\\test', 'timestamp': 1618488000, 'duration': 100000, 'playlist_index': 1, @@ -735,6 +736,9 @@ class TestYoutubeDL(unittest.TestCase): self.assertEqual(fname('Hello %(title1)s'), 'Hello $PATH') self.assertEqual(fname('Hello %(title2)s'), 'Hello %PATH%') + self.assertEqual(fname('%(title3)s'), 'foo_bar_test') + self.assertEqual(fname('%(formats.0)s'), "{'id' - 'id1'}") + self.assertEqual(fname('%(id)r %(height)r'), "'1234' 1080") self.assertEqual(fname('%(formats.0)r'), "{'id' - 'id1'}") diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 5b9cc235e..df6306fd0 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -915,7 +915,7 @@ class YoutubeDL(object): # If value is an object, sanitize might convert it to a string # So we convert it to repr first value, fmt = repr(value), '%ss' % fmt[:-1] - value = sanitize(key, value) + value = sanitize(key, value) tmpl_dict[key] = value return '%({key}){fmt}'.format(key=key, fmt=fmt)