Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,13 @@ func main() {
if strings.Contains(key, "=") {
return cli.NewExitError(fmt.Errorf("cannot use keys with '=' in environment: %s", key), codes.ErrorGeneric)
}

value, ok := item.Value.(string)
if !ok {
return cli.NewExitError(fmt.Errorf("cannot use non-string values in environment, got %T", item.Value), codes.ErrorGeneric)
value = fmt.Sprintf("%v", item.Value)
}

value = strings.ReplaceAll(value, "\n", "\\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is definitely wrong and must not be there.

Suggested change
value = strings.ReplaceAll(value, "\n", "\\n")

env = append(env, fmt.Sprintf("%s=%s", key, value))
}

Expand Down
7 changes: 6 additions & 1 deletion stores/dotenv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ func (store *Store) EmitPlainFile(in sops.TreeBranches) ([]byte, error) {
if comment, ok := item.Key.(sops.Comment); ok {
line = fmt.Sprintf("#%s\n", comment.Value)
} else {
value := strings.Replace(item.Value.(string), "\n", "\\n", -1)
value, ok := item.Value.(string)
if !ok {
value = fmt.Sprintf("%v", item.Value)
}

value = strings.ReplaceAll(value, "\n", "\\n")
Comment on lines +147 to +149
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replace only makes sense for strings:

Suggested change
}
value = strings.ReplaceAll(value, "\n", "\\n")
} else {
value = strings.ReplaceAll(value, "\n", "\\n")
}

line = fmt.Sprintf("%s=%s\n", item.Key, value)
}
buffer.WriteString(line)
Expand Down
Loading