Add non-interactive options for paste sanitization

This commit is contained in:
Kovid Goyal
2023-11-04 07:34:46 +05:30
parent 169315d33d
commit 995112d952
3 changed files with 10 additions and 2 deletions

View File

@@ -552,6 +552,10 @@ The supported paste actions are:
:code:`quote-urls-at-prompt`:
If the text being pasted is a URL and the cursor is at a shell prompt,
automatically quote the URL (needs :opt:`shell_integration`).
:code:`replace-dangerous-control-codes`
Replace dangerous control codes from pasted text, without confirmation.
:code:`replace-newline`
Replace the newline character from pasted text, without confirmation.
:code:`confirm`:
Confirm the paste if the text to be pasted contains any terminal control codes
as this can be dangerous, leading to code execution if the shell/program running

View File

@@ -911,11 +911,11 @@ def shell_integration(x: str) -> FrozenSet[str]:
def paste_actions(x: str) -> FrozenSet[str]:
s = frozenset({'quote-urls-at-prompt', 'confirm', 'filter', 'confirm-if-large'})
s = frozenset({'quote-urls-at-prompt', 'confirm', 'filter', 'confirm-if-large', 'replace-dangerous-control-codes', 'replace-newline'})
q = frozenset(x.lower().split(','))
if not q.issubset(s):
log_error(f'Invalid paste actions: {q - s}, ignoring')
return q & s or frozenset({'invalid'})
return (q & s) or frozenset({'invalid'})
return q