extend 'path-restrict' option

Allow its value to be a JSON object / Python dict that specifies
a mapping from invalid/unwanted input characters to specific
output characters.

For example {"/": "-", "*": "+"} will transform
"foo / ***bar***" into "foo - +++bar+++"

(closes #662, #755)
This commit is contained in:
Mike Fährmann
2020-05-22 01:14:10 +02:00
parent bcac31b7c7
commit bc53302ad6
2 changed files with 11 additions and 6 deletions

View File

@@ -690,6 +690,9 @@ class PathFormat():
def _build_cleanfunc(chars, repl):
if not chars:
return lambda x: x
elif isinstance(chars, dict):
def func(x, table=str.maketrans(chars)):
return x.translate(table)
elif len(chars) == 1:
def func(x, c=chars, r=repl):
return x.replace(c, r)