[nautilus/1841-crashing-when-copying-folder-with-same-name-and-click-to-rename] file-conflict-dialog: Fix crash on extensionless filenames
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/1841-crashing-when-copying-folder-with-same-name-and-click-to-rename] file-conflict-dialog: Fix crash on extensionless filenames
- Date: Thu, 29 Apr 2021 15:58:23 +0000 (UTC)
commit 87bb1b9b926a7a3f90b369aaab053a7d29a95fa7
Author: António Fernandes <antoniof gnome org>
Date: Thu Apr 29 16:36:47 2021 +0100
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
src/nautilus-file-conflict-dialog.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/src/nautilus-file-conflict-dialog.c b/src/nautilus-file-conflict-dialog.c
index 28fa972a3..fca33921d 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_index_after_basename (const gchar *filename)
+{
+ const gchar *offset;
+
+ offset = eel_filename_get_extension_offset (filename);
+
+ if (offset == NULL)
+ {
+ /* If filename has got no extension, we want to get the index of the
+ * terminating null byte comes after the basename. */
+ return (int) strlen (filename);
+ }
+
+ return g_utf8_pointer_to_offset (filename, offset);
+}
+
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_index_after_basename (dialog->conflict_name);
+ end_pos = get_index_after_basename (dialog->suggested_name);
gtk_editable_select_region (GTK_EDITABLE (dialog->entry), start_pos, end_pos);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]