Skip to content

Commit

Permalink
escape opt/arg values before printing as env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
unRob committed Feb 1, 2023
1 parent bf43645 commit 15f3f5c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/command/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func ArgumentsToEnv(cmd *command.Command, dst *[]string, prefix string) {
}
*dst = append(*dst, fmt.Sprintf("declare -a %s=(%s)", envName, strings.Join(ret, " ")))
} else {
*dst = append(*dst, fmt.Sprintf("%s%s=%s", prefix, envName, arg.ToString()))
*dst = append(*dst, fmt.Sprintf("%s%s=%s", prefix, envName, shellescape.Quote(arg.ToString())))
}
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func OptionsToEnv(cmd *command.Command, dst *[]string, prefix string) {
cmd.Cobra.Flags().VisitAll(func(f *pflag.Flag) {
envName, value := envValue(cmd.Options, f)
if envName != nil && value != nil {
*dst = append(*dst, fmt.Sprintf("%s%s=%s", prefix, *envName, *value))
*dst = append(*dst, fmt.Sprintf("%s%s=%s", prefix, *envName, shellescape.Quote(*value)))
}
})
}
Expand Down

0 comments on commit 15f3f5c

Please sign in to comment.