utils: Modify sanitize_filename(): convert invalid chars to hex representation,
patch 6493c04f9d8bdb7b1d2c037fdd66c337a7a91af5
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun May 31 00:26:34 CEST 2026
* utils: Modify sanitize_filename(): convert invalid chars to hex representation,
this makes the filenames deterministic for the same session,
and helps to not download a file more than once
hunk ./utils.py 21
-FILENAME_INVALID_CHARS = re.compile('[/{}<>()"\'\\|&#%?]')
+FILENAME_INVALID_CHARS = re.compile('[\0-\x1F/{}<>"\'\\|*&#%?\x7F]')
hunk ./utils.py 90
- cn = str(sanitize_filename.cn)
- new_fn, ns = FILENAME_INVALID_CHARS.subn(cn, fn)
- if ns:
- sanitize_filename.cn += 1
- return new_fn.strip('-').replace(' ','_')
-sanitize_filename.cn = 0
+ def hexize(m):
+ return '-{:x}-'.format(ord(m.group(0)))
+
+ new_fn = FILENAME_INVALID_CHARS.sub(hexize, fn)
+ return new_fn.lstrip('-').replace(' ','_')