core: do not consider bracketed pastes unsafe

This commit is contained in:
Mitchell Hashimoto
2023-11-04 12:08:34 -07:00
parent 85d4a9a572
commit 06a469fc4b

View File

@ -2500,10 +2500,22 @@ fn completeClipboardPaste(
) !void { ) !void {
if (data.len == 0) return; if (data.len == 0) return;
const critical: struct {
bracketed: bool,
} = critical: {
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
const bracketed = self.io.terminal.modes.get(.bracketed_paste);
// If we have paste protection enabled, we detect unsafe pastes and return // If we have paste protection enabled, we detect unsafe pastes and return
// an error. The error approach allows apprt to attempt to complete the paste // an error. The error approach allows apprt to attempt to complete the paste
// before falling back to requesting confirmation. // before falling back to requesting confirmation.
if (self.config.clipboard_paste_protection and //
// We do not do this for bracketed pastes because bracketed pastes are
// by definition safe since they're framed.
if (!bracketed and
self.config.clipboard_paste_protection and
!allow_unsafe and !allow_unsafe and
!terminal.isSafePaste(data)) !terminal.isSafePaste(data))
{ {
@ -2511,20 +2523,18 @@ fn completeClipboardPaste(
return error.UnsafePaste; return error.UnsafePaste;
} }
const bracketed = bracketed: {
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
// With the lock held, we must scroll to the bottom. // With the lock held, we must scroll to the bottom.
// We always scroll to the bottom for these inputs. // We always scroll to the bottom for these inputs.
self.scrollToBottom() catch |err| { self.scrollToBottom() catch |err| {
log.warn("error scrolling to bottom err={}", .{err}); log.warn("error scrolling to bottom err={}", .{err});
}; };
break :bracketed self.io.terminal.modes.get(.bracketed_paste); break :critical .{
.bracketed = bracketed,
};
}; };
if (bracketed) { if (critical.bracketed) {
// If we're bracketd we write the data as-is to the terminal with // If we're bracketd we write the data as-is to the terminal with
// the bracketed paste escape codes around it. // the bracketed paste escape codes around it.
_ = self.io_thread.mailbox.push(.{ _ = self.io_thread.mailbox.push(.{