From: Leonardo Taccari Date: Mon, 15 Oct 2018 15:31:53 +0000 (+0200) Subject: Gracefully handle subtleties of util_expand() of `~' and `~user'. X-Git-Url: https://git.owens.tech/wrapped.html/wrapped.html/git?a=commitdiff_plain;h=da6c5f85d56e715a2e4486387056920be06b3f23;p=vimb.git Gracefully handle subtleties of util_expand() of `~' and `~user'. 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. --- diff --git a/tests/test-util.c b/tests/test-util.c index ad3f1cb..35cf08d 100644 --- a/tests/test-util.c +++ b/tests/test-util.c @@ -17,6 +17,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ +#include #include #include @@ -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);