Always ask for confirmation when pasting text with control codes in it

This commit is contained in:
Kovid Goyal
2023-10-20 13:02:28 +05:30
parent 56963c693e
commit defa2e29ac
7 changed files with 32 additions and 19 deletions

View File

@@ -1135,16 +1135,13 @@ def docs_url(which: str = '', local_docs_root: Optional[str] = '') -> str:
return url
def sanitize_for_bracketed_paste(text: bytes, at_shell_prompt: bool = False) -> bytes:
def sanitize_for_bracketed_paste(text: bytes) -> bytes:
pat = re.compile(b'(?:(?:\033\\\x5b)|(?:\x9b))201~')
while True:
new_text = pat.sub(b'', text)
if new_text == text:
break
text = new_text
if at_shell_prompt:
# some shells dont handle C0 control codes in pasted text correctly
text = re.sub(b'[\x00-\x1f]+', b'', text)
return text