Gracefully handle subtleties of util_expand() of `~' and `~user'.
authorLeonardo Taccari <iamleot@gmail.com>
Mon, 15 Oct 2018 15:31:53 +0000 (17:31 +0200)
committerLeonardo Taccari <iamleot@gmail.com>
Mon, 15 Oct 2018 15:31:53 +0000 (17:31 +0200)
When `~' is expanded to an home directory without any user, g_get_home_dir()
function is used that on Unix systems first try to honor HOME and fall back to
the passwd file if not set.

On the other hand, `~user' is expanded always by checking the passwd
file.  Adjust test_expand_tilde_user() accordingly.

tests/test-util.c

index ad3f1cb..35cf08d 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program. If not, see http://www.gnu.org/licenses/.
  */
 
+#include <pwd.h>
 #include <gtk/gtk.h>
 #include <src/util.h>
 
@@ -88,9 +89,15 @@ static void test_expand_tilde_home(void)
 static void test_expand_tilde_user(void)
 {
     State state = {0};
-    const char *home = g_get_home_dir();
     const char *user = g_get_user_name();
+    const char *home;
     char *in, *out;
+    struct passwd *pwd;
+
+    /* initialize home */
+    pwd = getpwnam(user);
+    g_assert_nonnull(pwd);
+    home = pwd->pw_dir;
 
     /* don't expand within words */
     in = g_strdup_printf("foo~%s/bar", user);