Mercurial > vim
comparison src/cmdexpand.c @ 33521:1f9b1def80c8 v9.0.2009
patch 9.0.2009: cmdline-completion for comma-separated options wrong
Commit: https://github.com/vim/vim/commit/54844857fd6933fa4f6678e47610c4b9c9f7a091
Author: Yee Cheng Chin <ychin.git@gmail.com>
Date: Mon Oct 9 18:12:31 2023 +0200
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>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 09 Oct 2023 18:30:04 +0200 |
parents | 95db67c7b754 |
children | 46d449fd4fe4 |
comparison
equal
deleted
inserted
replaced
33520:3ea4f0cb88ac | 33521:1f9b1def80c8 |
---|---|
111 // Insert a backslash into a file name before a space, \, %, # | 111 // Insert a backslash into a file name before a space, \, %, # |
112 // and wildmatch characters, except '~'. | 112 // and wildmatch characters, except '~'. |
113 for (int i = 0; i < numfiles; ++i) | 113 for (int i = 0; i < numfiles; ++i) |
114 { | 114 { |
115 // for ":set path=" we need to escape spaces twice | 115 // for ":set path=" we need to escape spaces twice |
116 if (xp->xp_backslash == XP_BS_THREE) | 116 if (xp->xp_backslash & XP_BS_THREE) |
117 { | 117 { |
118 p = vim_strsave_escaped(files[i], (char_u *)" "); | 118 char *pat = (xp->xp_backslash & XP_BS_COMMA) ? " ," : " "; |
119 p = vim_strsave_escaped(files[i], (char_u *)pat); | |
119 if (p != NULL) | 120 if (p != NULL) |
120 { | 121 { |
121 vim_free(files[i]); | 122 vim_free(files[i]); |
122 files[i] = p; | 123 files[i] = p; |
123 #if defined(BACKSLASH_IN_FILENAME) | 124 #if defined(BACKSLASH_IN_FILENAME) |
126 { | 127 { |
127 vim_free(files[i]); | 128 vim_free(files[i]); |
128 files[i] = p; | 129 files[i] = p; |
129 } | 130 } |
130 #endif | 131 #endif |
132 } | |
133 } | |
134 else if (xp->xp_backslash & XP_BS_COMMA) | |
135 { | |
136 if (vim_strchr(files[i], ',') != NULL) | |
137 { | |
138 p = vim_strsave_escaped(files[i], (char_u *)","); | |
139 if (p != NULL) | |
140 { | |
141 vim_free(files[i]); | |
142 files[i] = p; | |
143 } | |
131 } | 144 } |
132 } | 145 } |
133 #ifdef BACKSLASH_IN_FILENAME | 146 #ifdef BACKSLASH_IN_FILENAME |
134 p = vim_strsave_fnameescape(files[i], vse_what); | 147 p = vim_strsave_fnameescape(files[i], vse_what); |
135 #else | 148 #else |
2728 free_pat = TRUE; | 2741 free_pat = TRUE; |
2729 pat = vim_strsave(pat); | 2742 pat = vim_strsave(pat); |
2730 for (i = 0; pat[i]; ++i) | 2743 for (i = 0; pat[i]; ++i) |
2731 if (pat[i] == '\\') | 2744 if (pat[i] == '\\') |
2732 { | 2745 { |
2733 if (xp->xp_backslash == XP_BS_THREE | 2746 if (xp->xp_backslash & XP_BS_THREE |
2734 && pat[i + 1] == '\\' | 2747 && pat[i + 1] == '\\' |
2735 && pat[i + 2] == '\\' | 2748 && pat[i + 2] == '\\' |
2736 && pat[i + 3] == ' ') | 2749 && pat[i + 3] == ' ') |
2737 STRMOVE(pat + i, pat + i + 3); | 2750 STRMOVE(pat + i, pat + i + 3); |
2738 if (xp->xp_backslash == XP_BS_ONE | 2751 else if (xp->xp_backslash & XP_BS_ONE |
2739 && pat[i + 1] == ' ') | 2752 && pat[i + 1] == ' ') |
2740 STRMOVE(pat + i, pat + i + 1); | 2753 STRMOVE(pat + i, pat + i + 1); |
2754 else if ((xp->xp_backslash & XP_BS_COMMA) | |
2755 && pat[i + 1] == '\\' | |
2756 && pat[i + 2] == ',') | |
2757 STRMOVE(pat + i, pat + i + 2); | |
2758 #ifdef BACKSLASH_IN_FILENAME | |
2759 else if ((xp->xp_backslash & XP_BS_COMMA) | |
2760 && pat[i + 1] == ',') | |
2761 STRMOVE(pat + i, pat + i + 1); | |
2762 #endif | |
2741 } | 2763 } |
2742 } | 2764 } |
2743 | 2765 |
2744 if (xp->xp_context == EXPAND_FILES) | 2766 if (xp->xp_context == EXPAND_FILES) |
2745 flags |= EW_FILE; | 2767 flags |= EW_FILE; |