mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-10 09:02:01 -07:00
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 ".
This commit is contained in:
committed by
Junegunn Choi
parent
0580fe9046
commit
c4185e81e8
@@ -1103,9 +1103,18 @@ func keyMatch(key int, event tui.Event) bool {
|
||||
event.Type == tui.Mouse && key == tui.DoubleClick && event.MouseEvent.Double
|
||||
}
|
||||
|
||||
func quoteEntryCmd(entry string) string {
|
||||
escaped := strings.Replace(entry, `\`, `\\`, -1)
|
||||
escaped = `"` + strings.Replace(escaped, `"`, `\"`, -1) + `"`
|
||||
r, _ := regexp.Compile(`[&|<>()@^%!"]`)
|
||||
return r.ReplaceAllStringFunc(escaped, func(match string) string {
|
||||
return "^" + match
|
||||
})
|
||||
}
|
||||
|
||||
func quoteEntry(entry string) string {
|
||||
if util.IsWindows() {
|
||||
return strconv.Quote(strings.Replace(entry, "\"", "\\\"", -1))
|
||||
return quoteEntryCmd(entry)
|
||||
}
|
||||
return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'"
|
||||
}
|
||||
|
Reference in New Issue
Block a user