Skip to content

Commit 5532954

Browse files
committed
Use shellescape.Quote instead of %q format for directory name
Because golang and shell quoting requirements are different. E.g. "foo$bar" really needs to be 'foo$bar' to avoid interpolation. Signed-off-by: Jan Dubois <[email protected]>
1 parent 7f79c49 commit 5532954

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cmd/limactl/shell.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,19 @@ func shellAction(cmd *cobra.Command, args []string) error {
8484
return err
8585
}
8686
if workDir != "" {
87-
changeDirCmd = fmt.Sprintf("cd %q || exit 1", workDir)
87+
changeDirCmd = fmt.Sprintf("cd %s || exit 1", shellescape.Quote(workDir))
8888
// FIXME: check whether y.Mounts contains the home, not just len > 0
8989
} else if len(y.Mounts) > 0 {
9090
hostCurrentDir, err := os.Getwd()
9191
if err == nil {
92-
changeDirCmd = fmt.Sprintf("cd %q", hostCurrentDir)
92+
changeDirCmd = fmt.Sprintf("cd %s", shellescape.Quote(hostCurrentDir))
9393
} else {
9494
changeDirCmd = "false"
9595
logrus.WithError(err).Warn("failed to get the current directory")
9696
}
9797
hostHomeDir, err := os.UserHomeDir()
9898
if err == nil {
99-
changeDirCmd = fmt.Sprintf("%s || cd %q", changeDirCmd, hostHomeDir)
99+
changeDirCmd = fmt.Sprintf("%s || cd %s", changeDirCmd, shellescape.Quote(hostHomeDir))
100100
} else {
101101
logrus.WithError(err).Warn("failed to get the home directory")
102102
}

0 commit comments

Comments
 (0)