patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Problem: MS-Windows: shell commands fail if &shell contains a space.
Solution: Use quotes instead of escaping. (closes #4920)
diff --git a/src/os_win32.c b/src/os_win32.c
index 26005b2..ce03557 100644
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -4490,8 +4490,25 @@
{
int ret;
WCHAR *wcmd;
+ char_u *buf;
+ size_t len;
- wcmd = enc_to_utf16((char_u *)cmd, NULL);
+ // If the command starts and ends with double quotes, enclose the command
+ // in parentheses.
+ len = STRLEN(cmd);
+ if (len >= 2 && cmd[0] == '"' && cmd[len - 1] == '"')
+ {
+ len += 3;
+ buf = alloc(len);
+ if (buf == NULL)
+ return -1;
+ vim_snprintf((char *)buf, len, "(%s)", cmd);
+ wcmd = enc_to_utf16(buf, NULL);
+ free(buf);
+ }
+ else
+ wcmd = enc_to_utf16((char_u *)cmd, NULL);
+
if (wcmd == NULL)
return -1;