diff --git a/cmd-source-file.c b/cmd-source-file.c index 7696dc92..ea477d1b 100644 --- a/cmd-source-file.c +++ b/cmd-source-file.c @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -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);