commit 41c1b9623e1d7ad2e745b977560b1f12fc566222
parent 555a9878447d68b26ed4d505b56d6ba8bf228d71
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Tue, 25 Feb 2025 17:24:25 +0100
input: make bracketed paste more robust against loss of closing sequence
A bracketed paste should be one large batch (or several batches)
of bytes, not single bytes coming in one by one. When the latter
happens, assume the end-of-paste sequence got swallowed somehow,
stop the bracketed paste and display a warning, while discarding
the first byte that came in alone.
This change was inspired by this report from Doug Smythies:
https://lists.gnu.org/archive/html/nano-devel/2025-02/msg00001.html
Diffstat:
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -1444,9 +1444,13 @@ void suck_up_input_and_paste_it(void)
cutbuffer = line;
while (bracketed_paste) {
+ size_t were_waiting = waiting_keycodes();
int input = get_kbinput(midwin, BLIND);
- if (input == '\r' || input == '\n') {
+ /* If key codes come singly, something is wrong. */
+ if (were_waiting == 0 && waiting_keycodes() == 0)
+ break;
+ else if (input == '\r' || input == '\n') {
line->next = make_new_node(line);
line = line->next;
line->data = copy_of("");
@@ -1457,7 +1461,7 @@ void suck_up_input_and_paste_it(void)
line->data[index++] = (char)input;
line->data[index] = '\0';
} else if (input != BRACKETED_PASTE_MARKER)
- beep();
+ break;
}
if (ISSET(VIEW_MODE))
@@ -1465,6 +1469,11 @@ void suck_up_input_and_paste_it(void)
else
paste_text();
+ if (bracketed_paste) {
+ statusline(ALERT, _("Flawed paste"));
+ bracketed_paste = FALSE;
+ }
+
free_lines(cutbuffer);
cutbuffer = was_cutbuffer;
}
diff --git a/src/winio.c b/src/winio.c
@@ -742,10 +742,8 @@ int convert_CSI_sequence(const int *seq, size_t length, int *consumed)
}
if (trailer != '~') {
- /* Broken -- assume a truncated end-of-paste sequence. */
- bracketed_paste = FALSE;
*consumed = length;
- return ERR;
+ return FOREIGN_SEQUENCE;
}
if (seq[2] == '0') {