From c4185e81e86e339ae2c18e5d9b596b7992ec179b Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 2 Oct 2017 11:36:19 -0400 Subject: Fix ExecCommandWith for cmd.exe in Windows (#1072) Close #1018 Run the command as is in cmd.exe with no parsing and escaping. Explicity set cmd.SysProcAttr so execCommand does not escape the command. Technically, the command should be escaped with ^ for special characters, including ". This allows cmd.exe commands to be chained together. See https://github.com/neovim/neovim/pull/7343#issuecomment-333350201 This commit also updates quoteEntry to use strings.Replace instead of strconv.Quote which escapes more than \ and ". --- src/terminal_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/terminal_test.go') diff --git a/src/terminal_test.go b/src/terminal_test.go index d42d2b82..60f2b1ad 100644 --- a/src/terminal_test.go +++ b/src/terminal_test.go @@ -91,3 +91,22 @@ func TestReplacePlaceholder(t *testing.T) { result = replacePlaceholder("echo {}/{1}/{3}/{2..3}", true, Delimiter{regex: regex}, false, "query", items1) check("echo ' foo'\\''bar baz'/'f'/'r b'/''\\''bar b'") } + +func TestQuoteEntryCmd(t *testing.T) { + tests := map[string]string{ + `"`: `^"\^"^"`, + `\`: `^"\\^"`, + `\"`: `^"\\\^"^"`, + `"\\\"`: `^"\^"\\\\\\\^"^"`, + `&|<>()@^%!`: `^"^&^|^<^>^(^)^@^^^%^!^"`, + `%USERPROFILE%`: `^"^%USERPROFILE^%^"`, + `C:\Program Files (x86)\`: `^"C:\\Program Files ^(x86^)\\^"`, + } + + for input, expected := range tests { + escaped := quoteEntryCmd(input) + if escaped != expected { + t.Errorf("Input: %s, expected: %s, actual %s", input, expected, escaped) + } + } +} -- cgit v1.2.3