1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00

Avoid panic when values are numbers

When decrypting to dotenv we try to escape new line in the values
without taking into account the possibility that the value could be
something different than a string (e.g. an int).

This used to cause a panic when using `decrypt --output-format dotenv`.

Signed-off-by: billy4479 <giachi.ellero@gmail.com>
This commit is contained in:
billy4479
2025-09-02 21:50:37 +02:00
parent 9e7c7597ea
commit ba010428ee

View File

@@ -141,7 +141,13 @@ 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 = stores.ValToString(item.Value)
} else {
value = strings.ReplaceAll(value, "\n", "\\n")
}
line = fmt.Sprintf("%s=%s\n", item.Key, value)
}
buffer.WriteString(line)