Mercurial > vim
comparison src/strings.c @ 25698:000b37efd5fa v8.2.3385
patch 8.2.3385: escaping for fish shell does not work properly
Commit: https://github.com/vim/vim/commit/6e82351130ddb8d13cf3748b47f07cae77886fc7
Author: Jason Cox <dev@jasoncarloscox.com>
Date: Sun Aug 29 12:36:49 2021 +0200
patch 8.2.3385: escaping for fish shell does not work properly
Problem: Escaping for fish shell does not work properly.
Solution: Insert a backslash before a backslash. (Jason Cox, closes https://github.com/vim/vim/issues/8810)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 29 Aug 2021 12:45:05 +0200 |
parents | 0082503ff2ff |
children | e9687a2f6fb3 |
comparison
equal
deleted
inserted
replaced
25697:c7845af77c65 | 25698:000b37efd5fa |
---|---|
120 */ | 120 */ |
121 int | 121 int |
122 csh_like_shell(void) | 122 csh_like_shell(void) |
123 { | 123 { |
124 return (strstr((char *)gettail(p_sh), "csh") != NULL); | 124 return (strstr((char *)gettail(p_sh), "csh") != NULL); |
125 } | |
126 | |
127 /* | |
128 * Return TRUE when 'shell' has "fish" in the tail. | |
129 */ | |
130 int | |
131 fish_like_shell(void) | |
132 { | |
133 return (strstr((char *)gettail(p_sh), "fish") != NULL); | |
125 } | 134 } |
126 | 135 |
127 /* | 136 /* |
128 * Escape "string" for use as a shell argument with system(). | 137 * Escape "string" for use as a shell argument with system(). |
129 * This uses single quotes, except when we know we need to use double quotes | 138 * This uses single quotes, except when we know we need to use double quotes |
143 char_u *p; | 152 char_u *p; |
144 char_u *d; | 153 char_u *d; |
145 char_u *escaped_string; | 154 char_u *escaped_string; |
146 int l; | 155 int l; |
147 int csh_like; | 156 int csh_like; |
157 int fish_like; | |
148 char_u *shname; | 158 char_u *shname; |
149 int powershell; | 159 int powershell; |
150 # ifdef MSWIN | 160 # ifdef MSWIN |
151 int double_quotes; | 161 int double_quotes; |
152 # endif | 162 # endif |
154 // Only csh and similar shells expand '!' within single quotes. For sh and | 164 // Only csh and similar shells expand '!' within single quotes. For sh and |
155 // the like we must not put a backslash before it, it will be taken | 165 // the like we must not put a backslash before it, it will be taken |
156 // literally. If do_special is set the '!' will be escaped twice. | 166 // literally. If do_special is set the '!' will be escaped twice. |
157 // Csh also needs to have "\n" escaped twice when do_special is set. | 167 // Csh also needs to have "\n" escaped twice when do_special is set. |
158 csh_like = csh_like_shell(); | 168 csh_like = csh_like_shell(); |
169 | |
170 // Fish shell uses '\' as an escape character within single quotes, so '\' | |
171 // itself must be escaped to get a literal '\'. | |
172 fish_like = fish_like_shell(); | |
159 | 173 |
160 // PowerShell uses it's own version for quoting single quotes | 174 // PowerShell uses it's own version for quoting single quotes |
161 shname = gettail(p_sh); | 175 shname = gettail(p_sh); |
162 powershell = strstr((char *)shname, "pwsh") != NULL; | 176 powershell = strstr((char *)shname, "pwsh") != NULL; |
163 # ifdef MSWIN | 177 # ifdef MSWIN |
195 if (do_special && find_cmdline_var(p, &l) >= 0) | 209 if (do_special && find_cmdline_var(p, &l) >= 0) |
196 { | 210 { |
197 ++length; // insert backslash | 211 ++length; // insert backslash |
198 p += l - 1; | 212 p += l - 1; |
199 } | 213 } |
214 if (*p == '\\' && fish_like) | |
215 ++length; // insert backslash | |
200 } | 216 } |
201 | 217 |
202 // Allocate memory for the result and fill it. | 218 // Allocate memory for the result and fill it. |
203 escaped_string = alloc(length); | 219 escaped_string = alloc(length); |
204 if (escaped_string != NULL) | 220 if (escaped_string != NULL) |
258 { | 274 { |
259 *d++ = '\\'; // insert backslash | 275 *d++ = '\\'; // insert backslash |
260 while (--l >= 0) // copy the var | 276 while (--l >= 0) // copy the var |
261 *d++ = *p++; | 277 *d++ = *p++; |
262 continue; | 278 continue; |
279 } | |
280 if (*p == '\\' && fish_like) | |
281 { | |
282 *d++ = '\\'; | |
283 *d++ = *p++; | |
263 } | 284 } |
264 | 285 |
265 MB_COPY_CHAR(p, d); | 286 MB_COPY_CHAR(p, d); |
266 } | 287 } |
267 | 288 |