[nautilus/1841-crashing-when-copying-folder-with-same-name-and-click-to-rename: 1/2] 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: 1/2] file-conflict-dialog: Fix crash on extensionless filenames
- Date: Fri, 30 Apr 2021 10:42:00 +0000 (UTC)
commit 4a99c7e15a1349172ca4593b14b4851ce6aef93f
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..4fe195e17 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 filename has got no extension, we want to get the index of the
+ * terminating null byte comes after the basename. */
+ return (int) g_utf8_strlen (filename);
+ }
+
+ 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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]