[gnome-commander/gcmd-1-14] on_new_textfile_ok: Add trailing separator at the URI path of current directory, fixing #119



commit 18cf3f2eb979bcc11e497858b021f71e30498293
Author: Maik Pertermann <maik tapse gmx de>
Date:   Sun Feb 13 19:04:09 2022 +0100

    on_new_textfile_ok: Add trailing separator at the URI path of current directory, fixing #119

 src/gnome-cmd-file-selector.cc | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/src/gnome-cmd-file-selector.cc b/src/gnome-cmd-file-selector.cc
index c5beee5e..6e84ca89 100644
--- a/src/gnome-cmd-file-selector.cc
+++ b/src/gnome-cmd-file-selector.cc
@@ -1106,13 +1106,20 @@ static gboolean on_new_textfile_ok (GnomeCmdStringDialog *string_dialog, const g
     GnomeCmdDir *dir = fs->get_directory();
     g_return_val_if_fail (GNOME_CMD_IS_DIR (dir), TRUE);
 
-    GError *error = nullptr;
     auto uriBaseString = static_cast<gchar*>(GNOME_CMD_FILE (dir)->get_uri_str());
+    // Let the URI to the current directory end with '/'
+    auto conLastCharacter = uriBaseString[strlen(uriBaseString)-1];
+    auto uriBaseStringSep = conLastCharacter == G_DIR_SEPARATOR
+        ? g_strdup(uriBaseString)
+        : g_strdup_printf("%s%s", uriBaseString, G_DIR_SEPARATOR_S);
+    g_free (uriBaseString);
+
     auto relativeFileNamePath = g_build_filename(".", fname, nullptr);
-    auto uriString = g_uri_resolve_relative (uriBaseString, relativeFileNamePath,
+    GError *error = nullptr;
+    auto uriString = g_uri_resolve_relative (uriBaseStringSep, relativeFileNamePath,
                                              G_URI_FLAGS_NONE, &error);
     g_free(relativeFileNamePath);
-    g_free (uriBaseString);
+    g_free (uriBaseStringSep);
     if (error)
     {
         gnome_cmd_string_dialog_set_error_desc (string_dialog, g_strdup_printf("%s", error->message));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]