Skip to content

Commit

Permalink
Correctly handle ' characters in output
Browse files Browse the repository at this point in the history
  • Loading branch information
brannondorsey committed Jul 1, 2020
1 parent 1f824d6 commit 8177346
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.2.0

* Wrap output values in single quotes so they can be `source`d correctly when they contain special characters.
* Replace `'`character in secrets value with `'"'"'` for proper escaping ([Stack Overflow reference](https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings)).

## v0.1.0

Initial public release.
5 changes: 4 additions & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ func HandleError(err error) {
func SecretsToEnvString(secrets map[string]string) string {
lines := make([]string, len(secrets))
for key, value := range secrets {
lines = append(lines, fmt.Sprintf("%s=%s\n", key, value))
// Escape single quotes via:
// https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings
escaped := strings.ReplaceAll(value, "'", "'\"'\"'")
lines = append(lines, fmt.Sprintf("%s='%s'\n", key, escaped))
}
sort.Strings(lines)
return strings.Join(lines, "")
Expand Down

0 comments on commit 8177346

Please sign in to comment.