diff options
author | Leonardo Taccari <iamleot@gmail.com> | 2018-10-15 17:31:53 +0200 |
---|---|---|
committer | Leonardo Taccari <iamleot@gmail.com> | 2018-10-15 17:31:53 +0200 |
commit | da6c5f85d56e715a2e4486387056920be06b3f23 (patch) | |
tree | 7761203c7b6ba6e6e77ff54421dee4e43e4f2af0 /tests | |
parent | 99f7810d1034b057f77bec4ae57ec080992ad9a9 (diff) |
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-util.c | 9 |
1 files changed, 8 insertions, 1 deletions
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 <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); |