aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/cache.py
diff options
context:
space:
mode:
Diffstat (limited to 'yt_dlp/cache.py')
-rw-r--r--yt_dlp/cache.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/yt_dlp/cache.py b/yt_dlp/cache.py
index 4f9fb78d3..7be91eae5 100644
--- a/yt_dlp/cache.py
+++ b/yt_dlp/cache.py
@@ -5,6 +5,7 @@ import os
import re
import shutil
import traceback
+import urllib.parse
from .utils import expand_path, traverse_obj, version_tuple, write_json_file
from .version import __version__
@@ -22,11 +23,9 @@ class Cache:
return expand_path(res)
def _get_cache_fn(self, section, key, dtype):
- assert re.match(r'^[a-zA-Z0-9_.-]+$', section), \
- 'invalid section %r' % section
- assert re.match(r'^[a-zA-Z0-9_.-]+$', key), 'invalid key %r' % key
- return os.path.join(
- self._get_root_dir(), section, f'{key}.{dtype}')
+ assert re.match(r'^[\w.-]+$', section), f'invalid section {section!r}'
+ key = urllib.parse.quote(key, safe='').replace('%', ',') # encode non-ascii characters
+ return os.path.join(self._get_root_dir(), section, f'{key}.{dtype}')
@property
def enabled(self):