Handle ~ correctly when loading a file, GitHub issue 3518.

This commit is contained in:
nicm
2025-11-01 16:42:59 +00:00
parent e5ab5995db
commit 8cb2805eb7

18
file.c
View File

@@ -44,13 +44,21 @@ RB_GENERATE(client_files, client_file, entry, file_cmp);
static char * static char *
file_get_path(struct client *c, const char *file) file_get_path(struct client *c, const char *file)
{ {
char *path; const char *home;
char *path, *full_path;
if (*file == '/') if (strncmp(file, "~/", 2) != 0)
path = xstrdup(file); path = xstrdup(file);
else else {
xasprintf(&path, "%s/%s", server_client_get_cwd(c, NULL), file); home = find_home();
return (path); if (home == NULL)
home = "";
xasprintf(&path, "%s%s", home, file + 1);
}
if (*path == '/')
return (path);
xasprintf(&full_path, "%s/%s", server_client_get_cwd(c, NULL), path);
return (full_path);
} }
/* Tree comparison function. */ /* Tree comparison function. */