aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-03-24 14:42:42 +0100
committerJustin M. Keyes <justinkz@gmail.com>2017-04-12 02:10:33 +0200
commitf7611d74e73329a4192666ff59911ff214f462ab (patch)
tree993b2b2fa4a849b531e7a143a506b98240f8bfdc
parentd6e5f94ae945308d96be414c9c1fb3f0ae71355e (diff)
downloadrneovim-f7611d74e73329a4192666ff59911ff214f462ab.tar.gz
rneovim-f7611d74e73329a4192666ff59911ff214f462ab.tar.bz2
rneovim-f7611d74e73329a4192666ff59911ff214f462ab.zip
win: vim_strsave_shellescape: Handle 'shellslash'.
From Vim, misc2.c:vim_strsave_shellescape
-rw-r--r--src/nvim/strings.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index 87e066d80a..8a1a3beddd 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -198,8 +198,16 @@ char_u *vim_strsave_shellescape(const char_u *string,
/* 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)) {
- if (*p == '\'')
- length += 3; /* ' => '\'' */
+#ifdef WIN32
+ if (!p_ssl) {
+ if (*p == '"') {
+ length++; // " -> ""
+ }
+ } else
+#endif
+ if (*p == '\'') {
+ length += 3; // ' => '\''
+ }
if ((*p == '\n' && (csh_like || do_newline))
|| (*p == '!' && (csh_like || do_special))) {
++length; /* insert backslash */
@@ -216,10 +224,25 @@ char_u *vim_strsave_shellescape(const char_u *string,
escaped_string = xmalloc(length);
d = escaped_string;
- /* add opening quote */
+ // add opening quote
+#ifdef WIN32
+ if (!p_ssl) {
+ *d++ = '"';
+ } else
+#endif
*d++ = '\'';
for (const char_u *p = string; *p != NUL; ) {
+#ifdef WIN32
+ if (!p_ssl) {
+ if (*p == '"') {
+ *d++ = '"';
+ *d++ = '"';
+ p++;
+ continue;
+ }
+ } else
+#endif
if (*p == '\'') {
*d++ = '\'';
*d++ = '\\';
@@ -246,7 +269,12 @@ char_u *vim_strsave_shellescape(const char_u *string,
MB_COPY_CHAR(p, d);
}
- /* add terminating quote and finish with a NUL */
+ // add terminating quote and finish with a NUL
+# ifdef WIN32
+ if (!p_ssl) {
+ *d++ = '"';
+ } else
+# endif
*d++ = '\'';
*d = NUL;