From f01dea8643e2956d2480ee12c3e5ee960944a49d Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 23 Feb 2023 19:57:18 +0100 Subject: [PATCH] Fix bracketed paste with EOT payload This works around an issue in many (all?) shells where the bracketed paste logic would only strip out `\r` but interpret EOT (`\x03`) as a termination of the bracketed paste. --- CHANGELOG.md | 1 + alacritty/src/event.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b82d1c9..7d19290e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Redraw hanging until a keypress on X11 in rare cases - Window clipping when maximizing a window without decorations on Windows - Quadrants not aligned with half blocks with built-in font +- EOT (`\x03`) escaping bracketed paste mode ### Removed diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index 5eafc09c..3ecca5e8 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -790,7 +790,15 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext for ActionCon } } else if self.terminal().mode().contains(TermMode::BRACKETED_PASTE) { self.write_to_pty(&b"\x1b[200~"[..]); - self.write_to_pty(text.replace('\x1b', "").into_bytes()); + + // Write filtered escape sequences. + // + // We remove `\x1b` to ensure it's impossible for the pasted text to write the bracketed + // paste end escape `\x1b[201~` and `\x03` since some shells incorrectly terminate + // bracketed paste on its receival. + let filtered = text.replace('\x1b', "").replace('\x03', ""); + self.write_to_pty(filtered.into_bytes()); + self.write_to_pty(&b"\x1b[201~"[..]); } else { // In non-bracketed (ie: normal) mode, terminal applications cannot distinguish