0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 9.0.2009: cmdline-completion for comma-separated options wrong

Problem:  cmdline-completion for comma-separated options wrong
Solution: Fix command-line expansions for options with filenames with
          commas

Fix command-line expansions for options with filenames with commas

Cmdline expansion for option values that take a comma-separated list
of file names is currently not handling file names with commas as the
commas are not escaped. For such options, the commas in file names need
to be escaped (to differentiate from a comma that delimit the list
items). The escaped comma is unescaped in `copy_option_part()` during
option parsing.

Fix as follows:
- Cmdline completion for option values with comma-separated file/folder
  names will not start a new match when seeing `\\,` and will instead
  consider it as one value.
- File/folder regex matching will strip the `\\` when seeing `\\,` to
  make sure it can match the correct files/folders.
- The expanded value will escape `,` with `\\,`, similar to how spaces
  are escaped to make sure the option value is correct on the cmdline.

This fix also takes into account the fact that Win32 Vim handles file
name escaping differently. Typing '\,' for a file name results in it
being handled literally but in other platforms '\,' is interpreted as a
simple ',' and commas need to be escaped using '\\,' instead.

Also, make sure this new logic only applies to comma-separated options
like 'path'. Non-list options like 'set makeprg=<Tab>' and regular ex
commands like `:edit <Tab>` do not require escaping and will continue to
work.

Also fix up documentation to be clearer. The original docs are slightly
misleading in how it discusses triple slashes for 'tags'.

closes: #13303
related: #13301

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
This commit is contained in:
Yee Cheng Chin
2023-10-09 18:12:31 +02:00
committed by Christian Brabandt
parent b07b9dc4da
commit 54844857fd
7 changed files with 168 additions and 18 deletions

View File

@@ -113,9 +113,10 @@ wildescape(
for (int i = 0; i < numfiles; ++i)
{
// for ":set path=" we need to escape spaces twice
if (xp->xp_backslash == XP_BS_THREE)
if (xp->xp_backslash & XP_BS_THREE)
{
p = vim_strsave_escaped(files[i], (char_u *)" ");
char *pat = (xp->xp_backslash & XP_BS_COMMA) ? " ," : " ";
p = vim_strsave_escaped(files[i], (char_u *)pat);
if (p != NULL)
{
vim_free(files[i]);
@@ -130,6 +131,18 @@ wildescape(
#endif
}
}
else if (xp->xp_backslash & XP_BS_COMMA)
{
if (vim_strchr(files[i], ',') != NULL)
{
p = vim_strsave_escaped(files[i], (char_u *)",");
if (p != NULL)
{
vim_free(files[i]);
files[i] = p;
}
}
}
#ifdef BACKSLASH_IN_FILENAME
p = vim_strsave_fnameescape(files[i], vse_what);
#else
@@ -2730,14 +2743,23 @@ expand_files_and_dirs(
for (i = 0; pat[i]; ++i)
if (pat[i] == '\\')
{
if (xp->xp_backslash == XP_BS_THREE
if (xp->xp_backslash & XP_BS_THREE
&& pat[i + 1] == '\\'
&& pat[i + 2] == '\\'
&& pat[i + 3] == ' ')
STRMOVE(pat + i, pat + i + 3);
if (xp->xp_backslash == XP_BS_ONE
else if (xp->xp_backslash & XP_BS_ONE
&& pat[i + 1] == ' ')
STRMOVE(pat + i, pat + i + 1);
else if ((xp->xp_backslash & XP_BS_COMMA)
&& pat[i + 1] == '\\'
&& pat[i + 2] == ',')
STRMOVE(pat + i, pat + i + 2);
#ifdef BACKSLASH_IN_FILENAME
else if ((xp->xp_backslash & XP_BS_COMMA)
&& pat[i + 1] == ',')
STRMOVE(pat + i, pat + i + 1);
#endif
}
}