From a268e9a268903ab8cea18891e14e476d19a997e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Fox?= Date: Thu, 19 Nov 2026 09:42:06 +0100 Subject: [PATCH] ev-window.c: Only use the base name of attachments when saving The attachment name comes from the document and was used as is to build the destination, so a name like ../Desktop/x.desktop wrote the file outside the folder picked in Save Attachment As. The same name was also suggested in the save dialog for a single attachment, where GTK resolves it the same way. Use g_path_get_basename for both, like ev_attachment_open already does for its temporary file. --- shell/ev-window.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/shell/ev-window.c b/shell/ev-window.c index 8ad585ea..6c0607f2 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -7216,14 +7216,17 @@ attachment_save_dialog_response_cb (GtkWidget *fc, EvAttachment *attachment; GFile *save_to = NULL; GError *error = NULL; + gchar *name; attachment = (EvAttachment *) l->data; + /* The name comes from the document, keep it inside the chosen folder */ + name = g_path_get_basename (ev_attachment_get_name (attachment)); if (is_native) { if (is_dir) { save_to = g_file_get_child (target_file, /* FIXMEchpe: file name encoding! */ - ev_attachment_get_name (attachment)); + name); } else { save_to = g_object_ref (target_file); } @@ -7239,6 +7242,7 @@ attachment_save_dialog_response_cb (GtkWidget *fc, "%s", _("The attachment could not be saved.")); g_error_free (error); g_object_unref (save_to); + g_free (name); continue; } @@ -7247,8 +7251,7 @@ attachment_save_dialog_response_cb (GtkWidget *fc, GFile *dest_file; if (is_dir) { - dest_file = g_file_get_child (target_file, - ev_attachment_get_name (attachment)); + dest_file = g_file_get_child (target_file, name); } else { dest_file = g_object_ref (target_file); } @@ -7260,6 +7263,7 @@ attachment_save_dialog_response_cb (GtkWidget *fc, } g_object_unref (save_to); + g_free (name); } g_free (uri); @@ -7295,9 +7299,12 @@ ev_attachment_popup_cmd_save_attachment_as (GtkAction *action, gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE); gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE); - if (attachment) - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), - ev_attachment_get_name (attachment)); + if (attachment) { + gchar *name = g_path_get_basename (ev_attachment_get_name (attachment)); + + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), name); + g_free (name); + } ev_window_file_chooser_restore_folder (window, GTK_FILE_CHOOSER (fc),