Use a regex for bracketed paste sanitization

This commit is contained in:
Kovid Goyal
2022-09-23 22:18:03 +05:30
parent dbb97a62bf
commit 26b8ab9adf
3 changed files with 38 additions and 27 deletions

View File

@@ -1086,3 +1086,13 @@ def docs_url(which: str = '', local_docs_root: Optional[str] = '') -> str:
if frag:
url += '#' + frag
return url
def sanitize_for_bracketed_paste(text: bytes) -> bytes:
pat = re.compile(b'(?:(?:\033\\[)|(?:\x9b))201~')
while True:
new_text = pat.sub(text, b'')
if new_text == text:
break
text = new_text
return text