mirror of
https://github.com/tmux/tmux.git
synced 2025-09-11 05:48:17 +00:00
Quote cwd for glob in a way that actually works, from Pavel Roskin in
GitHub issue 4623.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <stdlib.h>
|
||||
@@ -150,6 +151,21 @@ cmd_source_file_add(struct cmd_source_file_data *cdata, const char *path)
|
||||
cdata->files[cdata->nfiles++] = xstrdup(path);
|
||||
}
|
||||
|
||||
static char *
|
||||
cmd_source_file_quote_for_glob(const char *path)
|
||||
{
|
||||
char *quoted = xmalloc(2 * strlen(path) + 1), *q = quoted;
|
||||
const char *p = path;
|
||||
|
||||
while (*p != '\0') {
|
||||
if ((u_char)*p < 128 && !isalnum((u_char)*p) && *p != '/')
|
||||
*q++ = '\\';
|
||||
*q++ = *p++;
|
||||
}
|
||||
*q = '\0';
|
||||
return (quoted);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@@ -189,7 +205,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'v'))
|
||||
cdata->flags |= CMD_PARSE_VERBOSE;
|
||||
|
||||
utf8_stravis(&cwd, server_client_get_cwd(c, NULL), VIS_GLOB);
|
||||
cwd = cmd_source_file_quote_for_glob(server_client_get_cwd(c, NULL));
|
||||
|
||||
for (i = 0; i < args_count(args); i++) {
|
||||
path = args_string(args, i);
|
||||
|
Reference in New Issue
Block a user