Skip to content
Myr

Fix powershell escaping

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Rashil Gandhi · committed by Junegunn Choi · parent edac982 · Browse files · 2 files+10 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−10 removed

  • other:+10 added−10 removed

2 files+10 added−10 removed

modified:src/util/util_windows.go+9 added-9 removed
37 unmodified lines
38// can kill preview process with its child processes at once.39// NOTE: For "powershell", we should ideally set output encoding to UTF8,40// but it is left as is now because no adverse effect has been observed.41func ExecCommandWith(shell string, command string, setpgid bool) *exec.Cmd {42 var commandline string42 var cmd *exec.Cmd43 if strings.Contains(shell, "cmd") {44 commandline = fmt.Sprintf(` /v:on/s/c "%s"`, command)45 } else if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") {46 commandline = fmt.Sprintf(` -NoProfile -Command "& { %s }"`, command)47 }48 if len(commandline) == 0 {49 cmd := exec.Command(shell, "-c", command)44 cmd = exec.Command(shell)45 cmd.SysProcAttr = &syscall.SysProcAttr{46 HideWindow: false,47 CmdLine: fmt.Sprintf(` /v:on/s/c "%s"`, command),48 CreationFlags: 0,49 }50 return cmd51 }56 cmd := exec.Command(shell)5253 if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") {54 cmd = exec.Command(shell, "-NoProfile", "-Command", command)55 } else {56 cmd = exec.Command(shell, "-c", command)57 }58 cmd.SysProcAttr = &syscall.SysProcAttr{59 HideWindow: false,59 CmdLine: commandline,60 CreationFlags: 0,61 }62 return cmd63}
20 unmodified lines
modified:src/terminal_windows.go+1 added-1 removed
35 unmodified lines
36 return r.ReplaceAllStringFunc(escaped, func(match string) string {37 return "^" + match38 })39 } else if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") {40 escaped := strings.Replace(entry, `"`, `""`, -1)40 escaped := strings.Replace(entry, `"`, `\"`, -1)41 return "'" + strings.Replace(escaped, "'", "''", -1) + "'"42 } else {43 return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'"44 }
1 unmodified line