From 028cb2be2f844b6563ac906e8066df184753fa8c Mon Sep 17 00:00:00 2001 From: Francisco Miamoto Date: Mon, 31 May 2021 19:53:27 -0300 Subject: add extra quoting for shell cmd string on linux This solves an issue where we could not open files with names that contained spaces and single quotes. It also solves an issue of variable expansion for files with some kind of environment variables on the name e.g. '$USER.txt' --- pkg/commands/oscommands/os.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'pkg/commands/oscommands') diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index 2922313b8..cf050cf53 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -301,10 +301,15 @@ func sanitisedCommandOutput(output []byte, err error) (string, error) { // OpenFile opens a file with the given func (c *OSCommand) OpenFile(filename string) error { commandTemplate := c.Config.GetUserConfig().OS.OpenCommand + quoted := c.Quote(filename) + if c.Platform.OS == "linux" { + // Add extra quoting to avoid issues with shell command string + quoted = c.Quote(quoted) + quoted = quoted[1 : len(quoted)-1] + } templateValues := map[string]string{ - "filename": c.Quote(filename), + "filename": quoted, } - command := utils.ResolvePlaceholderString(commandTemplate, templateValues) err := c.RunCommand(command) return err -- cgit v1.2.3