From 93b3520c11cd645d595f6158bc0cc178238105c5 Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Tue, 10 Sep 2024 11:03:44 -0400 Subject: [PATCH] assistant: Prevent possible execution of generated terminal commands (#17647) Closes #17424 Release Notes: - Fixed an issue where commands generated by the terminal command could sometimes be executed without confirmation --- crates/assistant/src/terminal_inline_assistant.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/assistant/src/terminal_inline_assistant.rs b/crates/assistant/src/terminal_inline_assistant.rs index 479925b060..bb3f9d36bf 100644 --- a/crates/assistant/src/terminal_inline_assistant.rs +++ b/crates/assistant/src/terminal_inline_assistant.rs @@ -988,7 +988,7 @@ impl TerminalTransaction { pub fn push(&mut self, hunk: String, cx: &mut AppContext) { // Ensure that the assistant cannot accidentally execute commands that are streamed into the terminal - let input = hunk.replace(CARRIAGE_RETURN, " "); + let input = Self::sanitize_input(hunk); self.terminal .update(cx, |terminal, _| terminal.input(input)); } @@ -1003,6 +1003,10 @@ impl TerminalTransaction { terminal.input(CARRIAGE_RETURN.to_string()) }); } + + fn sanitize_input(input: String) -> String { + input.replace(['\r', '\n'], "") + } } pub struct Codegen {