mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 01:08:20 +00:00
vim-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 vim/vim#8810)
6e82351130
This commit is contained in:
@@ -190,6 +190,7 @@ char_u *vim_strsave_shellescape(const char_u *string,
|
||||
char_u *escaped_string;
|
||||
size_t l;
|
||||
int csh_like;
|
||||
bool fish_like;
|
||||
|
||||
/* Only csh and similar shells expand '!' within single quotes. For sh and
|
||||
* the like we must not put a backslash before it, it will be taken
|
||||
@@ -197,6 +198,10 @@ char_u *vim_strsave_shellescape(const char_u *string,
|
||||
* Csh also needs to have "\n" escaped twice when do_special is set. */
|
||||
csh_like = csh_like_shell();
|
||||
|
||||
// Fish shell uses '\' as an escape character within single quotes, so '\'
|
||||
// itself must be escaped to get a literal '\'.
|
||||
fish_like = fish_like_shell();
|
||||
|
||||
/* First count the number of extra bytes required. */
|
||||
size_t length = STRLEN(string) + 3; // two quotes and a trailing NUL
|
||||
for (const char_u *p = string; *p != NUL; MB_PTR_ADV(p)) {
|
||||
@@ -220,6 +225,9 @@ char_u *vim_strsave_shellescape(const char_u *string,
|
||||
++length; /* insert backslash */
|
||||
p += l - 1;
|
||||
}
|
||||
if (*p == '\\' && fish_like) {
|
||||
length++; // insert backslash
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate memory for the result and fill it. */
|
||||
@@ -267,6 +275,10 @@ char_u *vim_strsave_shellescape(const char_u *string,
|
||||
*d++ = *p++;
|
||||
continue;
|
||||
}
|
||||
if (*p == '\\' && fish_like) {
|
||||
*d++ = '\\';
|
||||
*d++ = *p++;
|
||||
}
|
||||
|
||||
MB_COPY_CHAR(p, d);
|
||||
}
|
||||
|
Reference in New Issue
Block a user