From 9f6927c1641535e8cd393eb08835ee3bd01b46de Mon Sep 17 00:00:00 2001 From: Ryo Nakano Date: Fri, 8 Nov 2024 22:07:56 +0900 Subject: [PATCH 1/3] TerminalWidget: Fix non administrative commands not being pasted --- src/Widgets/TerminalWidget.vala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Widgets/TerminalWidget.vala b/src/Widgets/TerminalWidget.vala index f26628c2dc..5fca58d0cf 100644 --- a/src/Widgets/TerminalWidget.vala +++ b/src/Widgets/TerminalWidget.vala @@ -547,6 +547,8 @@ namespace Terminal { }); dialog.present (); + } else { + feed_child (text.data); } } else { feed_child (text.data); From 230ab1029675c97c72f95d1df836f7f19e4e1173 Mon Sep 17 00:00:00 2001 From: Ryo Nakano Date: Fri, 8 Nov 2024 23:05:38 +0900 Subject: [PATCH 2/3] TerminalWidget: Refactor validated_feed to avoid nested code --- src/Widgets/TerminalWidget.vala | 59 +++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/src/Widgets/TerminalWidget.vala b/src/Widgets/TerminalWidget.vala index 5fca58d0cf..aed2d5cec8 100644 --- a/src/Widgets/TerminalWidget.vala +++ b/src/Widgets/TerminalWidget.vala @@ -525,35 +525,44 @@ namespace Terminal { // Check pasted and dropped text before feeding to child; private void validated_feed (string? text) { - if (text != null && text.validate ()) { - unowned var toplevel = (MainWindow) get_toplevel (); - if (!toplevel.unsafe_ignored && - Application.settings.get_boolean ("unsafe-paste-alert")) { - - string? warn_text = null; - if ("\n" in text) { - warn_text = _("The pasted text may contain multiple commands"); - } else if ("sudo" in text || "doas" in text) { - warn_text = _("The pasted text may be trying to gain administrative access"); - } + // Do nothing when text is invalid + if (text == null || !text.validate ()) { + return; + } - if (warn_text != null) { - var dialog = new UnsafePasteDialog (toplevel, warn_text, text.strip ()); - dialog.response.connect ((res) => { - dialog.destroy (); - if (res == Gtk.ResponseType.ACCEPT) { - feed_child (text.data); - } - }); + unowned var toplevel = (MainWindow) get_toplevel (); - dialog.present (); - } else { - feed_child (text.data); - } - } else { + // No user interaction because of user's preference or previous selection + if (toplevel.unsafe_ignored || + !Application.settings.get_boolean ("unsafe-paste-alert")) { + + feed_child (text.data); + return; + } + + string? warn_text = null; + if ("\n" in text) { + warn_text = _("The pasted text may contain multiple commands"); + } else if ("sudo" in text || "doas" in text) { + warn_text = _("The pasted text may be trying to gain administrative access"); + } + + // No user interaction for safe commands + if (warn_text != null) { + feed_child (text.data); + return; + } + + // Ask user for interaction for unsafe commands + var dialog = new UnsafePasteDialog (toplevel, warn_text, text.strip ()); + dialog.response.connect ((res) => { + dialog.destroy (); + if (res == Gtk.ResponseType.ACCEPT) { feed_child (text.data); } - } + }); + + dialog.present (); } private void update_theme () { From 391b3db0fa1108a9f59550c4bbb1c34be34753c4 Mon Sep 17 00:00:00 2001 From: Ryo Nakano Date: Sat, 9 Nov 2024 08:17:01 +0900 Subject: [PATCH 3/3] Fix condition inverted unintentionally --- src/Widgets/TerminalWidget.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/TerminalWidget.vala b/src/Widgets/TerminalWidget.vala index aed2d5cec8..ea5f234967 100644 --- a/src/Widgets/TerminalWidget.vala +++ b/src/Widgets/TerminalWidget.vala @@ -548,7 +548,7 @@ namespace Terminal { } // No user interaction for safe commands - if (warn_text != null) { + if (warn_text == null) { feed_child (text.data); return; }