From ba010428eed73b24576069db6da3f7df164ecbbf Mon Sep 17 00:00:00 2001 From: billy4479 Date: Tue, 2 Sep 2025 21:50:37 +0200 Subject: [PATCH] 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 --- stores/dotenv/store.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stores/dotenv/store.go b/stores/dotenv/store.go index 1e533341e..c6ec8b505 100644 --- a/stores/dotenv/store.go +++ b/stores/dotenv/store.go @@ -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)