summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2021-04-29 16:36:47 +0100
committerAntónio Fernandes <antoniof@gnome.org>2021-04-30 11:52:45 +0100
commit66e7223258b4a220f6987b6a9d7caca314a0c4ad (patch)
treeb5e7aef4ee5ced47ac77626fec0845566a51edb4
parent17e1cd13d5f1ae6834fa87e57f5379d151553854 (diff)
downloadnautilus-66e7223258b4a220f6987b6a9d7caca314a0c4ad.tar.gz
file-conflict-dialog: Fix crash on extensionless filenames
The new filename entry has the automatically suggested part of the name selected for convenience since 9108b4028b7f476b598bc664079fd6d115801b66 However, the logic for this relies on extensions offsets, causing crashes when failing to handle the extensionless case, which is common for folders. So, improve the logic here to handle extensionless filenames, looking at their length instead. Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/1841
-rw-r--r--src/nautilus-file-conflict-dialog.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/nautilus-file-conflict-dialog.c b/src/nautilus-file-conflict-dialog.c
index 28fa972a3..678f96323 100644
--- a/src/nautilus-file-conflict-dialog.c
+++ b/src/nautilus-file-conflict-dialog.c
@@ -191,6 +191,23 @@ entry_text_changed_cb (GtkEditable *entry,
}
}
+static int
+get_character_position_after_basename (const gchar *filename)
+{
+ const gchar *extension;
+
+ extension = eel_filename_get_extension_offset (filename);
+
+ if (extension == NULL)
+ {
+ /* If the filename has got no extension, we want the position of the
+ * the terminating null. */
+ return (int) g_utf8_strlen (filename, -1);
+ }
+
+ return g_utf8_pointer_to_offset (filename, extension);
+}
+
static void
on_expanded_notify (GtkExpander *w,
GParamSpec *pspec,
@@ -212,15 +229,11 @@ on_expanded_notify (GtkExpander *w,
* replace the "(1)" bits with with something more meaningful, so
* select this region for convenience. */
- const gchar *offset;
int start_pos;
int end_pos;
- offset = eel_filename_get_extension_offset (dialog->conflict_name);
- start_pos = g_utf8_pointer_to_offset (dialog->conflict_name, offset);
-
- offset = eel_filename_get_extension_offset (dialog->suggested_name);
- end_pos = g_utf8_pointer_to_offset (dialog->suggested_name, offset);
+ start_pos = get_character_position_after_basename (dialog->conflict_name);
+ end_pos = get_character_position_after_basename (dialog->suggested_name);
gtk_editable_select_region (GTK_EDITABLE (dialog->entry), start_pos, end_pos);
}