From f27b50ae42bce241495e41f31670ba492382a52a Mon Sep 17 00:00:00 2001 From: Juhani Krekelä Date: Sat, 3 Jul 2021 00:03:03 +0300 Subject: Only allow opening local directories The proposed OSC 7 specification mandates [1] that the file:// URI includes the hostname, so that the terminal emulator can ignore remotely used programs' attempts to set the current working directory. However, VTE does not check the hostname component, and neither does launch_default_for_uri. Thus currently if one tries to open directory after running a remote program that used OSC 7, weltschmerz tries to open a file manager pointing at corresponding path on the local computer. weltschmerz already contains a function that checks the URI kept by VTE and returns the path only if it is on the local computer. This commit changes open_directory() to first use that, and then create a new local file:// URI based on it, unifying the behaviour of 'Open directory' and 'Open terminal'. [1] https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/20#note_294252 --- terminal.vala | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/terminal.vala b/terminal.vala index fcd5ee0..86f086f 100644 --- a/terminal.vala +++ b/terminal.vala @@ -374,7 +374,16 @@ class Terminal : Gtk.Overlay { [GtkCallback] void open_directory() { - uri_open(vte.get_current_directory_uri()); + var cwd = get_local_directory_path(); + if (cwd == null) + return; + + try { + uri_open(Filename.to_uri(cwd)); + } catch (Error e) { + warning(e.message); + infobar_show(e.message, Gtk.MessageType.ERROR); + } } void vte_copy(bool html = false) { @@ -402,7 +411,7 @@ class Terminal : Gtk.Overlay { copy_item_text.set_sensitive(vte.get_has_selection()); copy_item_html.set_sensitive(vte.get_has_selection()); open_terminal_item.set_sensitive(get_local_directory_path() != null); - open_directory_item.set_sensitive(vte.get_current_directory_uri() != null); + open_directory_item.set_sensitive(get_local_directory_path() != null); standard_context_menu.popup_at_pointer(event); } return true; -- cgit v1.2.3-2-gb3c3